开发者

Pagination in Codeigniter with join

I had my pagination working but then the structure of the database changed so it now doesn’t work because I have to join two tables to get the results I once had…

My db script is:

$query = $this->db->select('*');
$query = $this->db->from('user_entry'); 
$query = $this->db->join('user_details', 'user_entry.UserID = user_details.id'); 
$query = $this->db->limit($limit, $offset); 
$query = $this->db->get();

If you could help me, I woul开发者_如何学JAVAd be so grateful - thanks.


I still don't think there's enough information.. but pagination needs to know the total rows in order to create the links. Assuming this code is in your model and you're calling the model function from your controller in order to set the pagination config variables:

$this->db->select('*');
$this->db->from('user_entry');
$this->db->join('user_details', 'user_details.id = user_entry.UserID');
$this->db->limit($limit, $offset);
$query = $this->db->get();
return $query->num_rows();

in your controller:

$config['base_url'] = 'http://yoururl.com/controller/function';
$config['total_rows'] = $this->model_name->function(); // Model and function to the code above
$config['per_page'] = 10; // # of results you want to display per page
$config['num_links'] = 10; // # of pagination links you want to display
$this->pagination->initialize($config);

in your view where you want the pagination displayed:

<?=$this->pagination->create_links();?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜