如何在codeigniter中使用like和在like中使用多列联接表

时间:2019-06-01 05:47:28

标签: codeigniter

如何在codeigniter中使用带有like的联接表,以及在like中使用多列。

$ search_input = $ this-> input-> get('search_input',true);

   if($search_input!=''){


     $this->db->like('block.name','building.name' ,$search_input);


   } 
   $tempdb = clone $this->db;
   $total_row=  $tempdb->from('block')->count_all_results();
   $this->db->limit($perpage, $page); 
   $this->db->order_by("block.id", "desc");
  $this->db->join('building','building.id=block.building_name');

   $result = $this->db->select('block.id,block.name,building.name as building_name')->get('block')->result_array();
   $data=array();
   $data['block_data'] = $result;

1 个答案:

答案 0 :(得分:0)

尝试此代码

$this->db->group_start();
$this->db->like('block.name',$search_input);
$this->db->or_like('building.name', $search_input);
$this->db->group_end();