【问题标题】:codeigniter pagination total_rows dynamicallycodeigniter 分页 total_rows 动态
【发布时间】:2013-04-01 06:25:54
【问题描述】:

这是我的代码和注释行中的问题。

public function sonuc()
{
    $config['total_rows'] = 5  //i want to set here count of result instead of digit. count($data['sonuc']) does not work.. what will i do?
    $config['per_page'] = 2;
    $data['sonuc'] = $this->emlak_model->arama(
                        $config['per_page'], 
                        $this->uri->segment(3,0),
                        $this->input->post('semt'),
                     ); 
}

如果我用数字手动进行,分页将起作用,但我想自动获取查询的总行数,我该怎么办?谢谢。

【问题讨论】:

  • 您可以打印$data['sonuc'] 并向我们展示结果吗?设置$data['sonuc'] 后是否尝试设置$config['total_rows'] = count($data['sonuc']);
  • 我在#codeigniter irc 频道帮助了这个人,它已经解决了!
  • @JeremieGes 那么你或 Yigit 可以发布答案吗?

标签: codeigniter pagination


【解决方案1】:

如果您想在每次页面加载时对您的字段进行新计数,则必须使用查询计数来计算所有字段:

$total_rows = $this->db->count_all_results('mytable');

查看Codeigniter Doc

所以根据你的代码:

public function sonuc()
{
    $config['total_rows'] = $this->db->count_all_results('mytable'); //put your table name here 
    $config['per_page'] = 2;
    $data['sonuc'] = $this->emlak_model->arama(
                        $config['per_page'], 
                        $this->uri->segment(3,0),
                        $this->input->post('semt'),
                     ); 
}

【讨论】:

  • 我解决了我的问题,我现在看到了你的问题。 $this->db->count_all_results 不适合我。因为结果会根据用户的选择动态变化。 :) 我运行查询 2 次,首先我得到查询的计数,然后我处理查询。
猜你喜欢
  • 1970-01-01
  • 2014-06-23
  • 2011-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-14
相关资源
最近更新 更多