• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
search in codeigniter

#1
hello 

i have 2 table 

1 customer 
-----------------------------------------------------
id   | cusname            | phone
1    | any1                  |00000
2    | any2                  |12333



2 invoice 
-------------------------------------------------------
id  | cusid      |  any
1   | 1
2   | 1
3   | 2
4   | 2
5   | 1


i want search in table 2 with name in table 1 

get id from table 1 to 


i try 


custmodel

public function get_cust_id($search)
    {
$this->db->select('id');
$this->db->from('customer ');
$this->db->like('cusname ', $search);
$query = $this->db->get();
return $query->row_array(); 
    }
 


in invoice model 
$custtid=$this->cust_model->get_cust_id($search_string);

$this->db->where('cusd',$custtid);
Reply

#2
You need to use a join to join the two tables.

You could do something like:

PHP Code:
$this->db->from('invoice');
$this->db->join('customer''invoive.cusid  = customer.cid');
$this->db->like('cusname '$search); 

Since a customer can have more than one invoice, I would suggest you check the query with something like:

PHP Code:
$query $this->db->get();
if (
$query->num_rows() > 0)
{
 
  $results $query->result_array();
}
else
{
 
  $results FALSE;


There are some great help documents on all this:
http://www.codeigniter.com/user_guide/da...eries.html
http://www.codeigniter.com/user_guide/da...sults.html

Best wishes,

Paul.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.