如何检查哪个类似Codeigniter的查询在多个类似中返回数据



我试图了解如何检查类似查询的返回数据。用户可以搜索为1。位置2。供应商名称,3。类别名称。假设用户搜索印度,印度也可以提供供应商名称。现在,查询返回一些结果作为位置,另一些结果作为供应商名称。我想将位置匹配结果存储到位置数组中vendor名称匹配将结果输入vendor_name数组,然后返回两个数组。

这是我的型号

<?php 
class Search_M extends CI_Model{
public function getSearchResults($search_query){
$this->db->select('ov_activity.activity_id,ov_activity.timing,vendor_name,vendor_img,address');
$this->db->from('ov_activity');
$this->db->join('ov_vendors', 'ov_activity.vendor_id = ov_vendors.vendor_id','left');
$this->db->join('ov_category', 'ov_activity.category_id = ov_category.category_id','left');
$this->db->like('ov_vendors.vendor_name', $search_query);
$this->db->or_like('ov_vendors.address', $search_query);
$this->db->or_like('category_name', $search_query);
$query  =   $this->db->get();
return $query->result();
}
}
?>

这是我的控制器

<?php
public function search_post() {
$is_valid_token  = $this->authorization_token->validateToken();
if(!empty($is_valid_token) AND $is_valid_token['status'] === TRUE)
{
$searchData = array();
$searchData['query'] = $this->post('query');
$getSearchResults = $this->Search_M->getSearchResults($searchData['query']);
echo "<pre>";
print_r($getSearchResults);
exit;
}
?>

Try Below逻辑,

function filter_record($result,$searchKeyword) {
$setArr = array(); 
$setArr['Location'] =  array();
$setArr['Cat'] = array(); 
$setArr['Vendor'] = array(); 
foreach($result as $row) {
if (stristr($row->location_field, $searchKeyword) ) {
$setArr['Location'][] = $row;
}else if (stristr($row->cat_field, $searchKeyword) ) {
$setArr['Cat'][] = $row;
}else if (stristr($row->vendor_field, $searchKeyword) ) {
$setArr['Vendor'][] = $row;
}

}
return   $setArr;
}

相关内容

  • 没有找到相关文章

最新更新