mysql query help needed - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: mysql query help needed (/showthread.php?tid=18265) |
mysql query help needed - El Forum - 04-30-2009 [eluser]LuckyFella73[/eluser] Hi codeigniters, I'm struggling with building a query and I bet it's a 10 seconds job for all the sql pros out there The scenario: I have a table called "maintable" where there is a column named "image_id" and a second table called "images" where I have the columns "id","image" and "logo". Each "image_id" entry from "maintable" is related to the "id" of the "images" table. I need a query to get all rows (and all columns) of the "maintable" and the related infos ("image" and "logo") in one rush maybe someone can help me with this? I had a simular thing a couple of year ago but I can't get it to work for this case... In the end I would like to have this in my view file: Code: <?php Would be very nice to get a hint! Maybe it's better to write down the table structures: table "maintable" (simplified): | id | title | date | image_id | display | ------------------------------------------------------------ | 1 | test | 2008 | 3 | yes | | 2 | test2 | 2009 | 7 | no | table "images": | id | image | logo | ----------------------------------------- | ... | 3 | image_a.gif | logo_a.jpg | | ... | 7 | image_b.gif | logo_b.jpg | ...and so on mysql query help needed - El Forum - 04-30-2009 [eluser]TheFuzzy0ne[/eluser] Code: $this->db->select('title, date, image, logo'); That should do it, I haven't tested it though. (2 minutes 8 seconds) mysql query help needed - El Forum - 04-30-2009 [eluser]LuckyFella73[/eluser] I bet the only reason you needed 2 minutes 8 seconds was you were replying to 27 other posts simultaneously ;-) Thank you soo much !! |