|
由于要对查询出的结果使用分页,可是不知道控制器该怎么写,总是出现没有参数的错误
Error Number: 1327
Undeclared variable: $offset
SELECT * FROM person WHERE flag = 1 LIMIT $offset,$limit
Filename: E:\xampp\htdocs\CI\system\database\DB_driver.php
Line Number: 330
求高人教教这个该怎么弄啊,不胜感激。。。。
代码如下:
PHP复制代码 //这是模块里的查询函数
function fir($offset='',$limit=''){
if($offset==0&&$limit==0){
return $this->db->query("SELECT * FROM person WHERE flag = 1 ");
}else{
return $this->db->query('SELECT * FROM person WHERE flag = 1 LIMIT $offset,$limit');
}
} 复制代码PHP复制代码 //这是控制器里的index
function index( ){
$this->load->helper('url');
$this->load->model('Allview_model','',TRUE); //加载模型
$this->load->library('pagination');
$limit = 5; // 每个单独分页显示的条目数
$config['base_url'] = base_url().'Allview/index/';
$config['total_rows'] = $this->Allview_model->fir(0,0)->num_rows();
$config['per_page'] = $limit;
$this->pagination->initialize($config);
$data['fir_data'] = $this->Allview_model->fir($offset = $this->uri->segment(3,0),$limit)->result();
$data['pagination'] = $this->pagination->create_links();
$this->load->view('fir_view',$data);
}
复制代码
|
|