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
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']."'/>";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.