search in codeigniter |
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);
You need to use a join to join the two tables.
You could do something like: PHP Code: $this->db->from('invoice'); 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(); 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. |
Welcome Guest, Not a member yet? Register Sign In |