codeigniter pagination total_rows动态

时间:2013-03-31 16:46:22

标签: codeigniter pagination

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

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'),
                     ); 
}

如果我用数字手动执行,分页将起作用,但我想自动获得total_row查询,我该怎么办?感谢。

1 个答案:

答案 0 :(得分:0)

如果您希望在每次加载页面时重新计算字段数,则必须使用查询计数计算所有字段:

$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'),
                     ); 
}