Codeigniter,设置分页

编程入门 行业动态 更新时间:2024-10-24 18:20:39
本文介绍了Codeigniter,设置分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以,我有一个问题,在我的网站上设置分页。

So, i'm having a problem to setting up pagination on my site.

首先,如果我在我的网站的第一页,并按下以进入第2页,1仍保持粗体。虽然我可以看到在网址,我在第2页。

First of all, if i'm at the first page of my site, and pressing to go to page 2, the "1" still stays bold. Though i can see in the url that i am at page 2.

其次,我需要一些帮助,以正确检索数据。如果我在第1页,我想得到所有的记录1-10。如果我在第2页,我想从11-20得到所有的记录。

Secondly, i need some help to retrieve the data correctly. If i am at page 1, i want to get all records 1-10. If i am on page 2, i want to get all records from 11-20. Got it?

我有google'd并尝试找到任何解决方案,但没有成功。

I have google'd and tried to find any solution, without any success.

$this->db->select('*'); $this->db->from('comments'); $this->db->where('comments.url_friendly', $id); $this->db->join('allt', 'allt.url_friendly = comments.url_friendly', 'left'); $this->db->order_by('comments.date', 'asc'); $data['query'] = $this->db->get(); $data['title'] = 'Kommentarer - '.$data['query']->row()->amne; $config['base_url'] = base_url(). 'kommentarer/'.$data['query']->row()->url_friendly; $config['total_rows'] = $data['query']->num_rows(); $config['per_page'] = 10; $this->pagination->initialize($config); $data['pagination'] = $this->pagination->create_links();

此外,我使用的代码在post 2,在此主题。

Also, i'm using the code in post 2, in this thread.

是的

推荐答案

$qry = "select * from comment c left join allt a on c.url_friendly = a.url_friendly where c.url_friendly = {$id}"; $per_page = 10; $offset = ($this->uri->segment(3) != '' ? $this->uri->segment(3):0);//this will get the current page(assuming that page number is in 3rd uri segment). if youy on page one,this will be set to zero $config['base_url'] = base_url(). 'kommentarer/'.$data['query']->row()->url_friendly; $config['total_rows'] = $this->db->query($qry)->num_rows(); $config['per_page'] = $per_page; $config['uri_segment'] = 3; //this is dependent to where your page number displays in url $this->pagination->initialize($config); $qry .= " limit {$per_page} offset {$offset} "; $data['result'] = $this->db->query($qry)->result(); $data['pagination'] = $this->pagination->create_links();

希望这将有所帮助。

更多推荐

Codeigniter,设置分页

本文发布于:2023-11-02 08:27:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551892.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分页   Codeigniter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!