【问题标题】:A problem with pagination codeigniter (page 2 not showing)分页 codeigniter 的问题(第 2 页未显示)
【发布时间】:2011-05-10 03:20:12
【问题描述】:

当我使用分页codeigniter显示来自数据库的数据时,我卡住了,第一页显示正确,但是当我点击第2页时,页数被选中但它仍然显示第1页的数据,所以用next页。这是我的代码

$id = $this->uri->segment(3);
$perpage = 5;
$this->load->library('pagination');
$config['base_url'] = base_url().'index.php/contname/method/'.$id;
$config['total_rows'] = $this->feedbackmodel->count_itemscat($id);
$config['per_page'] = $perpage;
$config['uri_segment'] = 4;
$this->pagination->initialize($config);

请任何人帮助我 提前致谢!

【问题讨论】:

  • 这看起来不错。我们还需要查看您的数据库查询。
  • 关于uri的部分,我已经修复了,谢谢!

标签: php codeigniter pagination


【解决方案1】:

检查您的模型,您是如何获取页面数据的。您必须在该函数中设置您要查找的页面,例如

    function getPage($count = 5, $from = 0) { // params are important
    $this->db->select('*', FALSE);

    ..........

    $query = $this->db->get('your_table', $count, $from); // <- that's important: $count, $from

    return $query->result();
}

听起来您缺少“来自”参数或类似的东西

【讨论】:

  • 我已经修复了在控制器中添加这个:$offset = $this->uri->segment(4)。谢谢!
  • 太棒了!我怀疑偏移问题出在模型中,而不是在控制器中。
  • 不好意思,好久没打开stackoverflow了,已经采纳答案了,谢谢:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-07
  • 2014-07-03
  • 1970-01-01
  • 1970-01-01
  • 2015-04-27
  • 1970-01-01
  • 2017-11-11
相关资源
最近更新 更多