2013-01-11 62 views
0

好吧,我一直在这个过去的一个小时,不能为我的生活弄清楚这一点。 这是说限制2,25 ..当然,跳过两个应该显示的行...我仍然在第1页,链接甚至不显示!我认为第一页应该是0,25,因为它显示了应显示在第一页上的所有行。CodeIgniter分页不显示应显示的所有行

到目前为止,我只有5行,但它只显示了其中的3个......前两行没有显示查询最初生成,直到添加LIMIT子句。 这里是我的编程明智:

public function category($id, $page = NULL) { 
    //grab topics 
    parent::before(); 
    $data['forum_title'] = $this->forum->get_cat($id); 
    $data['id'] = $id; 

    $config = array(); 
    $config['base_url'] = base_url() . 'forum/category/'; 
    $config['total_rows'] = $this->forum->topic_count($id); 
    $config['per_page'] = 25; 
    $config['uri_segment'] = 4; 

    $this->pagination->initialize($config); 

    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0; 
    $data['topics_array'] = $this->forum->get_topics($id, $config['per_page'], $page); 

    $data['links'] = $this->pagination->create_links(); 
    $this->load->view('forum/category', $data); 
    parent::after(); 
} 

我承认我不懂URI_SEGMENT考验..我有点事,但不是真的。我正在按照教程来生成这个。但是,我打印我的$限制和$开始变量和限制是25,因为它应该是,但开始打印为2 ..当我认为它应该是0在第一页。因为还没有25个结果,所以甚至不应该有第二页。

这里是我的函数来生成这些。 count_all_results()函数起作用(总共返回5个结果)。但是,只要添加LIMIT子句,get_topics()函数就不能正常工作。

//count the topics in a certain category id for pagination 
public function topic_count($id) { 
    $this->db->where('cat_id', $id); 
    $this->db->from('forum_topic'); 

    return $this->db->count_all_results(); 

} 
//get all topics in a certain category 
public function get_topics($id, $limit, $start) { 
    $this->db->distinct(); 
    $this->db->select('t.id, t.title, t.sticky, t.locked, u.username as author, COUNT(p.id) as postcount, (SELECT u.username 
     FROM forum_post fp 
     INNER JOIN user u ON fp.author_id = u.user_id 
     WHERE fp.topic_id = t.id 
     ORDER BY fp.date DESC 
     LIMIT 1) as lposter, (SELECT fp.date 
     FROM forum_post fp 
     WHERE fp.topic_id = t.id 
     ORDER BY fp.date DESC 
     LIMIT 1) as lastdate'); 
    $this->db->from('forum_topic t'); 
    $this->db->join('user u', 'u.user_id = t.author_id', 'inner'); 
    $this->db->join('forum_post p', 'p.topic_id = t.id', 'inner'); 
    $this->db->where('t.cat_id', $id); 
    $this->db->group_by('t.id, t.title, t.sticky, t.locked, author, lposter, lastdate'); 
    $this->db->order_by('t.sticky desc, p.date desc'); 
    $this->db->limit($limit, $start); 
    return $this->db->get()->result(); 
} 

我的网址我在现在的问题是论坛/分类/ 2 ...所以我假设的页面将是这样的:论坛/分类/ 2/1第1页,论坛/分类/第2页2/2等。正确? 因此,我将4作为URI段,因为它位于第4个参数位置。

任何帮助,将不胜感激......

EDITTTTTTTTT

好有人帮助我与此有关。但是,当我点击第2页时(我现在将限制降低到5,并且当前有7个结果,因此它生成了第2页...它将用5代替ID 2(类别ID 2)..而不是去第2页?? .... 2应该看起来像这样:forum/category/2/2 ...但是它是这样做的:论坛/ category/5

回答

2

您正在使用2个不同的URI段。您正在初始化分页对象4,然后您发送段3到get_topics()(因为$this->uri->segment(3))。您应该可能使用3,因为URI段从0开始不是1。 ,无论你使用3还是4,你都应该在两个地方使用同一个。使用$this->uri->segment($config['uri_segment'])而不是$this->uri->segment(3)

+0

敬畏的工作。然而,当我点击第2页时(我现在将限制降低到5,目前有7个结果,因此它生成了第2页...它将用5替换ID 2(类别ID为2)..而不是到第2页?? ....第2页应该看起来像这样:论坛/类别/ 2/2 ...但相反,它是这样做的:论坛/类别/ 5 – Peanut

+0

页码未在URL中表示 - 这是如果你每页显示10个结果,你会得到类别/ 0,category/10,category/20现在,/ 2/2被5取代,这可能是你的uri段设置,尝试增加1。 – Kira