ci分页问题,请帮忙解决下
本帖最后由 liaomars 于 2011-1-6 11:52 编辑这是我的控制器,分页的方法
<?php
/*
* Author@Liaobingbing
* liaoyunyu@gmail.com
* 留言本condeigniter
*/
date_default_timezone_set('Asia/Shanghai');
class Feedback extends Controller {
function __construct() {
parent::Controller();
$this->load->helper('url');
$this->load->helper('form');
$this->load->helper('date');
}
function _pagelist($method, $total, $perpage=2) {
$config['base_url'] = base_url() . 'index.php/' . 'Feedback/' . $method . '/';
$config['total_rows'] = $total;
$config['per_page'] = $perpage;
return $config;
}
function message_list() {
$this->load->library('pagination');
$this->load->model("Feed", '', true);
$rows = (int) $this->db->count_all('feed');
// echo $rows;
$conf = $this->_pagelist('message_list', $rows);
// print_r($conf);
$this->pagination->initialize($conf);
$offset = (int) $this->uri->segment(3);
echo $offset;
$sql = "SELECT * FROM feed ;";
//$this->db->select('*')->from('feed')->limit($offset, $conf['per_page']);
//$data['result'] = $this->db->get('feed',$offset,$conf['per_page']);
$data['result'] = $this->db->query($sql, array($offset, $conf['per_page']));
$data['include'] = "head";
$data['view_message'] = "view_message";
$data['title'] = "查看留言";
$this->load->view('view_message', $data);
}
}
?>
这是视图页面。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $title;?></title>
<base href="<?php echo base_url();?>"/>
<style type="text/css">
body{ margin:0px; padding:0px; font-size:12px; font-family:微软雅黑,Verdana, Geneva, sans-serif;}
div,ul,li,form,dl,dt,dd,table,td{margin:0px; padding:0px; }
.feed{ width:800px; margin:0 auto; }
.nav{ height:30px; line-height:30px; background:#9a9898; width:800px; overflow:hidden; margin-top:5px;}
.nav ul li{ float:left; width:90px; text-align:center; display:block; font-size:14px;}
.table{border:solid 1px #ccc; border-collapse: collapse; margin: 5px 0px; }
.table td{border:solid 1px #ccc; height: 30px; }
</style>
</head>
<body>
<div class="feed">
<?php $this->load->view($include);?>
<?php
foreach($result->result() as $rs){
?>
<table width="500" border="0" cellspacing="0" cellpadding="0" align="center" class="table">
<tr>
<td colspan="2">标题:<?php echo $rs->title;?></td>
</tr>
<tr>
<td width="218">时间:<?php echo $rs->addtime;?></td>
<td width="282">IP地址:<?php echo $rs->ipaddress;?></td>
</tr>
<tr>
<td colspan="2"><?php echo $rs->content;?></td>
</tr>
</table>
<?php}?>
<div><?php echo $this->pagination->create_links();?></div>
</div>
</body>
</html>
我现在数据库有四条数据。我设置每页为2条,但是打开页面还是4条。好像控制器那个查询语句的limit没有起作用。我找了手册。也试过用不同的查询语句。不行。请高手帮忙解答下。在这谢谢了:handshake $sql = "SELECT * FROM feed ;";
$data['result'] = $this->db->query($sql, array($offset, $conf['per_page']));
第一句有问题吧,你没写占位符
应该是
$sql = "SELECT * FROM feed limit ?,?"; 回复 2# Hex
谢谢管理员。帮我解决问题了
页:
[1]