Codeigniter activerecord查询具有精确结果的多个值

时间:2016-09-15 09:51:46

标签: activerecord

我有一个查询过滤与类别和子类别以及标签/属性(颜色,长度,连接等)相关的产品,并且我在使用$ this-> db-> where_in获取确切结果时遇到问题“场”,$ array_of_tags);还有另外一个乳清,我还没弄明白吗? 这是我的功能 `public function get_public_products($ limit_start = false,$ limit_end = false,$ categoria = false,$ subcategoria = false,$ tags = false){

    if(!$subcategoria){
        $this->db->select('*');
    }
    $this->db->from('products');
    if($categoria && !$subcategoria){
        $this->db->join('products_categories', 'products.familia = products_categories.codigo');
        $this->db->where('products_categories.slug',$categoria);
    }
    if($subcategoria && !$tags){
        $this->db->select('products.familia AS familia, products.subfamilia AS subfamilia, products.slug AS pslug, products_categories.slug AS cslug , products.nombre AS nombre, products_categories.name AS cname, products.codigo_producto AS codigo_producto');
        $this->db->join('products_categories', 'products.subfamilia = products_categories.codigo');         
        $this->db->where('products_categories.slug',$subcategoria);                 
    }

    if($tags){
        $this->db->select('products.familia AS familia, products.subfamilia AS subfamilia, products.slug AS pslug, products_categories.slug AS cslug , products.nombre AS nombre, products_categories.name AS cname, products.codigo_producto AS codigo_producto , products_tags_values.value AS tvalue, products_tags_values.slug AS tslug');
        $this->db->join('products_categories', 'products.subfamilia = products_categories.codigo'); 
        $this->db->where('products_categories.slug',$subcategoria); 

        $this->db->join('products_tags_values', 'products_tags_values.pid = products.codigo_producto');
        $tags_array = explode(",", $tags);
        $this->db->where_in('products_tags_values.slug',$tags_array);   

    }

    if($limit_start){
        $this->db->limit($limit_start, $limit_end); 
    }       

    $query = $this->db->get();
    return $query->result_array();      
}`

当我使用$this->db->where('products_tags_values.slug',"blue");时,这样可以正常工作,但如果我为多个标签使用这样的话,则不行。 $this->db->where('products_tags_values.slug',"blue");
$this->db->where('products_tags_values.slug',"20-m");

0 个答案:

没有答案