[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
// simplified of course ...
foreach ($query->result() as $row)
{
echo($row->title); // comes from table "maintable"
//
echo($row->date); // comes from table "maintable"
//
echo($row->image); // comes from table "images"
//
echo($row->logo); // comes from table "images"
// etc.
}
?>
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