【发布时间】:2015-11-26 08:40:15
【问题描述】:
我正在对我的模型中的大型数据库进行复杂查询,并且需要在限制分页结果之前计算总行数。
我的模型如下:
public function get_categoryads($limit, $start, $cid, $type)
{
$this->db->start_cache();
// All your conditions without limit
$this->db->from();
$this->db->where(); // and etc...
$this->db->stop_cache();
$total_rows = $this->db->count_all_results(); // This will get the real total rows
// Limit the rows now so to return per page result
$this->db->limit($per_page, $offset);
$result = $this->db->get();
return array(
'total_rows' => $total_rows,
'result' => $result,
);
}
我不明白现在如何在我的控制器中调用它。 1.获取要交给视图的结果 2. 获取total_rows 交给控制器中的分页配置。 如何在控制器中调用结果数组和总行数?
在我的控制器中:
// call the model function to get the result List data if not in an array
$data['results'] = $this->my_model->get_categoryads(10, 0, $cid, $type);
当模型推出一个数组时,这肯定行不通... 然后我应该在我的控制器中做些什么来获得以下信息:
// call the model function to get the result List data if not in an array
$data['results'] = $this->my_model->get_categoryads(10, 0, $cid, $type);
// Get total results for Pagination Config:
$config['total_rows'] = $this->db->count_all_results();
我做吗
$config['total_rows'] = $this->db->count_all_results($data['results']);
【问题讨论】:
标签: php mysql codeigniter