Welcome Guest, Not a member yet? Register   Sign In
Searching multiple tables - fields
#4

(This post was last modified: 10-18-2019, 08:06 AM by Wouter60.)

Try this:

controller:
PHP Code:
$this->load->helper('array');
$this->load->model('company_model');
$data['city'] = 'New York';  //example of city in your search box
$data['category'] = 15;    //example of category_id in your search box
$s_result $this->company_model->search_result($data);
echo 
'<pre>';
print_r($s_result);
echo 
'</pre>'

company_model:
PHP Code:
public function search_result($data)
{
  $s_category element('category',$data,NULL);  //element is array helper function!
  $s_city element('city',$data,NULL);
  $s_name element('name',$data,NULL);

  $this->db
  
->select('cot.*,cit.*,cat.*')
  ->from('company_table cot')
  ->join('company_information_table cit','cot.company_id = cit.company_id')
  ->join('category_table cat','cot.category_id=cat.category_id');
  if ($s_category$this->db->where('cot.category_id',$s_category);
  if ($s_city$this->db->where('cit.company_city',$s_city);
  if ($s_name$this->db->where('cot.company_name',$s_name);
  $this->db->order_by('cot.company_id','ASC');
  $query $this->db->get();
  if ($query->num_rows() == 0) {
    return FALSE;
  }
  else {
    return $query->result();
  }

Reply


Messages In This Thread
Searching multiple tables - fields - by demyr - 10-16-2019, 02:41 AM
RE: Searching multiple tables - fields - by demyr - 10-16-2019, 01:24 PM
RE: Searching multiple tables - fields - by Wouter60 - 10-16-2019, 11:00 PM
RE: Searching multiple tables - fields - by demyr - 10-20-2019, 11:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB