Reputation: 91
I have these 2 tables that I need the boat and image info from to show in the same sql/loop.
Is this possible? With inner join?
$info1 = mysql_query(" SELECT image1 as image, boat1 as boat FROM all_images ");
$info2 = mysql_query(" SELECT image2 as image, boat2 as boat FROM all_boats_images ");
while($b = mysql_fetch_array($????????)){
echo $b['boat'].$b['boat'];
}
Upvotes: 0
Views: 66
Reputation: 183
i think you want to use an union since you commented that the tables are not related
SELECT image1 as image, boat1 as boat FROM all_images
union all
SELECT image2 as image, boat2 as boat FROM all_boats_images
Upvotes: 0
Reputation: 2022
Hope this helps:
$query = mysql_query("SELECT all_images.image1, all_boats_images.image2 AS image FROM all_images, all_boat_images");
while($b = mysql_fetch_array($query))
{
echo $b['boat'];
}
To narrow down your results, try changing the $query to:
$query = mysql_query("SELECT all_images.image1, all_boats_images.image2 AS image FROM all_images, all_boat_images WHERE all_images.id = all_boats_images.id AND all_images.id = whatever_id_you_are_searching_for");
Upvotes: 0
Reputation: 3641
just append database name before your table name
i.e. if database name is db1 and table name is tb1 then
SELECT * FROM db1.tb1;
Upvotes: 1