1 回答
TA贡献1873条经验 获得超9个赞
事情在您的配置中 - 如果您有需要的字段,则必须对查询进行分组
以下应该做的工作
你的控制器
public function product()
{
$searchText="";
if($this->input->post('searchText'))
{
$searchText = $this->input->post('searchText');
}
$arrFilter = [
'like' => [
'ProductName' => $searchText
],
'orlike' => [
'CategoryName' => $searchText,
'SubCategoryName' => $searchText,
'BrandName' => $searchText
],
];
$jointables = [
'categories'=>'CategorySlug=ProductCategory',
'subcategories'=>'SubCategorySlug=ProductSubCategory',
'brands'=>'BrandSlug=ProductBrand'
];
$where = [
'ProductIsActive'=>1,
'ProductStatus'=>'Approved'
];
$data['product']= $this->Custom_model-> getproduct('products',$jointables,$where,$arrFilter);
}
你的模型
function getproduct($primarytable, $jointables, $where, $arrFilter = [])
{
$this->db->select('*');
$this->db->from($primarytable);
$this->db->where($where);
if (is_array($arrFilter) && count($arrFilter) > 0)
{
$this->db->group_start();
if (isset($arrFilter['like']))
{
$this->db->like($arrFilter['like']));
}
if (isset($arrFilter['orlike']))
{
$this->db->group_start();
foreach($arrFilter['orlike'] as $key=>$value)
{
if($value!="")
{
$this->db->or_like($key,$value,'both');
}
}
$this->db->group_end();
}
$this->db->group_end();
}
foreach($jointables as $key=>$value)
{
$this->db->join($key,$value,'left');
}
$query = $this->db->get();
if($query->num_rows() > 0)
{
$row = $query->result();
return $row;
}
else
{
return FALSE;
}
}
- 1 回答
- 0 关注
- 80 浏览
添加回答
举报