I'm trying to pull multiple rows from different tables in a database.
If I only have the first 3 rows from two tables, it works fine. As soon as I add the third table and try and pull another row it breaks!
Ultimately what I'm trying to do is pull the image, the dayid
, the name of a person, and then name of a cause.
The imageURL
and the Outfitday_id
are in the same table, the name of the person is in the table Pilot
, and the name of the cause is in the table cause.
For some reason it will pull the first two rows (imageUrl
, outfitDay_id
) from the table Outfitimage
, then pull the 3rd row (name
) from Pilot
, but fails if I add the name and try and pull it from the Cause
table.
$link = mysql_connect("host","user","pass");
if ($link) {
mysql_selectdb("up",$link);
// Select records from the DB
$query = "SELECT imageUrl,outfitDay_id,name,name FROM OutfitImage,Pilot,Cause ORDER BY Rand(" . date("Ymd") . ") LIMIT 1";
$image = mysql_query($query);
// Display records from the table
echo "";
while ($row = mysql_fetch_array($image, MYSQL_NUM)) {
echo "<IMAGE SOURCE='$row[0]'/><br>";
echo "<div id='info'>Day $row[1] of ";
echo "$row[2] Uniform Project for$row[3] </div>";
}
echo "";
} else {
echo "Can't connect to the database!";
}