我有4种类型的
doping
。
我需要在类别页面上进行一些排序。
根据形成日期,掺杂类型 1 和 4 的产品将列为 DESC 在顶部,类型 1 的产品在底部,类型 4 的产品在底部,正常产品在最后一行。
最后,我需要在视图中使用
doping
类型,以便我可以写出兴奋剂名称。
public function getdopingoneandfor($category_id)
{
$this->db->select('products.*, products.id as product_id, products_details.price as product_price');
$this->db->from('products');
$this->db->join('products_details', 'products_details.product_id = products.id');
$this->db->join('dopings', 'dopings.product_id = products.id');
$this->db->where('products.status', 1);
$this->db->where_in('dopings.type', array(1, 4));
$this->db->where('dopings.end_date >= CURDATE()');
$this->db->where('products.category_id', $category_id);
$this->db->group_by('products.id');
$this->db->order_by('MAX(dopings.created_at)', 'DESC');
$query = $this->db->get();
return $query->result();
}
这种查询方式看起来不太可能,而且扩展查询危害极大。 我建议你把它分成几部分。 如果您的客户在这个问题上非常坚持,请不要工作。