CodeIgniter Forums
Joins as array - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Joins as array (/showthread.php?tid=37259)



Joins as array - El Forum - 01-04-2011

[eluser]skribe[/eluser]
Sorry my brain has vacated the premises and so I'm having difficulties attempting to loop through an array to produce a join. ie
Code:
$joins = array(
                   array('contact', 'contact.id = person.id', 'left'),
                   array('info', 'info.id = person.id','left)
                             );

                foreach($joins as $join){
                   foreach($join as $item) {                    
                        something
                   }
                    $this->db->join(something);
                }

Any suggestions?


Joins as array - El Forum - 01-04-2011

[eluser]Techno Heart[/eluser]
Are you trying to pass the join variable in to a query ? what you exactly looking for ??be clear..


Joins as array - El Forum - 01-04-2011

[eluser]Atharva[/eluser]
It is sometimes better to use simple sql queries(i.e w/o Active Record) rather than making things complicated like you are doing.


Joins as array - El Forum - 01-04-2011

[eluser]skribe[/eluser]
I'm actually adapting this crud model which doesn't have a multi-table capability.


Joins as array - El Forum - 01-04-2011

[eluser]Atharva[/eluser]
Code:
$joins = array(
                   array('contact', 'contact.id = person.id', 'left'),
                   array('info', 'info.id = person.id','left')
                             );

                foreach($joins as $join){
                   $this->db->join($join[0], $join[1], $join[2]);
                    
                }

Is this what you are looking for?


Joins as array - El Forum - 01-04-2011

[eluser]skribe[/eluser]
That's exactly what I was after. Thank you.