Jump to content

SELECT from mutiple tables


hansman

Recommended Posts

Hello all, I have about 5 tables in a database that stroe pictures. I want to have one page where all the pictures come out. This is my code.

 

$query = "SELECT * FROM Wood_Destroying_Insects"; 

$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
echo "<img src='saveimg.php?id=".$row['id']."'/>";

 

ideas?

Link to comment
https://forums.phpfreaks.com/topic/118620-select-from-mutiple-tables/
Share on other sites

Just add these:

 

Note: Of course you can get tricky and use arrays to make the code more compact, but its not neccisarrily needed.

I believe you can use sql joins, but I havn't quite figured those out, but might as well experiment.

 

$query = "SELECT * FROM Wood_Destroying_Insects"; 
$query2 = "SELECT * FROM 2"; 
$query3 = "SELECT * FROM 3"; 
$query4 = "SELECT * FROM 4"; 
$query5 = "SELECT * FROM 5"; 

$result = mysql_query($query) or die(mysql_error());
$result2 = mysql_query($query2) or die(mysql_error());
$result3 = mysql_query($query3) or die(mysql_error());
$result4 = mysql_query($query4) or die(mysql_error());
$result5 = mysql_query($query5) or die(mysql_error());


while($row = mysql_fetch_array($result)){
echo "<img src='saveimg.php?id=".$row['id']."'/>";
}
while($row = mysql_fetch_array($result2)){
echo "<img src='saveimg.php?id=".$row['id']."'/>";
}
while($row = mysql_fetch_array($result3)){
echo "<img src='saveimg.php?id=".$row['id']."'/>";
}
while($row = mysql_fetch_array($result4)){
echo "<img src='saveimg.php?id=".$row['id']."'/>";
}
while($row = mysql_fetch_array($result5)){
echo "<img src='saveimg.php?id=".$row['id']."'/>";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.