使用$ this-> db->查询的Codeigniter分页无法正常工作

时间:2012-07-23 10:17:51

标签: php sql codeigniter-2

Url - localhost/ci/test/test_que/1

$sql="
select qo.id,
       qo.text 
FROM quiz_question qq,
quiz_question_option qo 
WHERE qq.id='".$qid."' 
AND qq.id=qo.quiz_question_id";

$q=$this->db->query($sql,$num,$qid);

如何实施?如何设置分页?

1 个答案:

答案 0 :(得分:0)

private function total_rows($sql){
$Query = $this->db->query($sql);
return $Query->num_rows();

}

$this->load->library('pagination');

$config['base_url'] = 'localhost/ci/test/test_que/1'; //your base url
$config['uri_segment'] = 3; //set URI Segment
$config['total_rows'] = $this->total_rows($sql); //your sql query for counting rows
$config['per_page'] = 10; //files or questions per page


$this->pagination->initialize($config); //put this in view 

多数民众赞成