如图所示,我在模型下具有以下功能..
public function get_products($category, $brand, $filter, $page, $limit) {
// output
$output = "";
// offset
$offset = $limit * ($page - 1);
// query for pagination
$this->db->select("*");
$this->db->from("products");
$this->db->where("category", $category);
if ($brand != "all") {
$this->db->where("brand", $brand);
}
// first time use
$query = $this->db->get();
$total_rows = $query->num_rows();
$this->db->limit($limit, $offset);
switch ($filter) {
case 'latest':
$this->db->order_by("released", "ASC");
break;
case 'most-viewed':
$this->db->order_by("views", "ASC");
break;
case 'price-low-to-high':
$this->db->order_by("price", "DESC");
break;
case 'price-high-to-low':
$this->db->order_by("price", "ASC");
break;
}
//second time use
$query = $this->db->get();
在这里,我想使用select
,from
和where
2this->db->get()
如您所见,但查询在运行第一个get()
. 那么有没有办法做到这一点?或者我必须写两次活动记录?
我尝试这样做的原因是为了获得num_rows
分页total_rows
配置的限制。