本文整理汇总了PHP中Base_Model::count_by方法的典型用法代码示例。如果您正苦于以下问题:PHP Base_Model::count_by方法的具体用法?PHP Base_Model::count_by怎么用?PHP Base_Model::count_by使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Base_Model
的用法示例。
在下文中一共展示了Base_Model::count_by方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: paginate
public function paginate($page = 1, $where = array(), $limit = 10)
{
// get filtered results
$where = array_merge($where, $this->where);
$offset = $page <= 1 ? 0 : ($page - 1) * $limit;
$this->db->limit($limit, $offset);
$results = parent::get_many_by($where);
// get counts (e.g. for pagination)
$count_results = count($results);
$count_total = parent::count_by($where);
$total_pages = ceil($count_total / $limit);
$counts = array('from_num' => $count_results == 0 ? 0 : $offset + 1, 'to_num' => $count_results == 0 ? 0 : $offset + $count_results, 'total_num' => $count_total, 'curr_page' => $page, 'total_pages' => $count_results == 0 ? 1 : $total_pages, 'limit' => $limit);
return array('data' => $results, 'counts' => $counts);
}
示例2: paginate
public function paginate($page = 1, $where = array(), $limit = NULL)
{
// decide per-page limit by: 1) $this->limit; 2) a default value (10)
if (!empty($this->limit) && $limit === NULL) {
$limit = $this->limit;
} else {
if ($limit === NULL) {
$limit = 10;
}
}
// avoid overrided by $this->limit
$this->limit = NULL;
// get filtered results
$where = array_merge($where, $this->where);
$offset = $page <= 1 ? 0 : ($page - 1) * $limit;
$this->db->limit($limit, $offset);
$results = parent::get_many_by($where);
// get counts (e.g. for pagination)
$count_results = count($results);
$count_total = parent::count_by($where);
$total_pages = ceil($count_total / $limit);
$counts = array('from_num' => $count_results == 0 ? 0 : $offset + 1, 'to_num' => $count_results == 0 ? 0 : $offset + $count_results, 'total_num' => $count_total, 'curr_page' => $page, 'total_pages' => $count_results == 0 ? 1 : $total_pages, 'limit' => $limit);
return array('data' => $results, 'counts' => $counts);
}