Codeigniter 3 order_by dopings

mrfwxfqh  于 4个月前  发布在  其他
关注(0)|答案(1)|浏览(34)

我有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();
    }

字符串

daupos2t

daupos2t1#

这种查询方式似乎是不可能的,并且扩展查询是极其有害的。我建议您将其分成几部分。如果您的客户在这个问题上非常坚持,请不要工作。

相关问题