0

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

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

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

4

1 回答 1

0

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

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

检查Codeigniter 文档

所以根据你的代码:

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'),
                     ); 
}
于 2013-03-31T22:25:54.173 回答