CodeIgniter Forums
Error on trying to join tables - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Error on trying to join tables (/showthread.php?tid=67559)



Error on trying to join tables - cybersven - 03-09-2017

Hi all,

Need help, I've tried a lot of things but it doesn't work.
An image is better to understand, here my two tables
http://www.hostingpics.net/viewer.php?id=545640Capturedecran20170309a121741.png

So for a simple example, I would like to get all columns from 'client' + column 'name' from 'contact'


My actual function is :
PHP Code:
public function get_client($client_id)
 
     {

 
           $this->db->where('client_id'$client_id);
 
           $query $this->db->get('client');
 
           if($query->num_rows()!==0)
 
           {
 
                 return $query->result();
 
           }
 
           else
            
{
 
                 return FALSE;
 
           }
 
     
This function works and I would like to add the column 'name'

I tear my hair I will not have any more :-)


RE: Error on trying to join tables - neuron - 03-09-2017

PHP Code:
$query $this->db->select('cl.*, ct.name')
->
from('client cl')
->
join('contact ct','cl.client_id = ct.client_id')
->
where('cl.client_id'$client_id)
->
get(); 

https://www.codeigniter.com/userguide3/database/query_builder.html


RE: Error on trying to join tables - InsiteFX - 03-09-2017

CodeIgniter Users Guide

See: The Query Builder join method.


RE: Error on trying to join tables - cybersven - 03-09-2017

That's what I've done but I was writing :
$this->db...
$this->db...

probably something wrong in the code, but now with your code it's working.
thx u

and I read the doc ^^

P.S. : I thing I know why ! I specified get('client')....