Multiple queries in loop
Posted: Mon Jun 07, 2010 6:27 pm
Hi,
I am quering mysql database to get the name of an image, and then attaching the name of the image to a list tag. this way I can poplulate the list with images dynamically:
<?php
$query = "SELECT filename from files";
$result = db_query($query);
print "<ul>";
{
while($row=db_fetch_array($result))
{
$filename = $row['filename'];
print "<li><a href=\"/sites/mysite.com/files/$filename\" class=\"01\"><img src=\"/sites/mysite.com/files/$filename\" /></a></li>\n";
}
}
print "</ul>\n";
?>
The above code works fine, but I also want to add an image description inside this <li>:
print "<li><h1>$description</h1><a href=\"/sites/mysite.com/files/$filename\" class=\"01\"><img src=\"/sites/mysite.com/files/$filename\" /></a></li>\n";
So each image in a list item will also have a description.
The problem is that the description of the image is in a completely different table in the database: SELECT description from upload
So how do I make this happen for the description part. the filename php is working good.
I am quering mysql database to get the name of an image, and then attaching the name of the image to a list tag. this way I can poplulate the list with images dynamically:
<?php
$query = "SELECT filename from files";
$result = db_query($query);
print "<ul>";
{
while($row=db_fetch_array($result))
{
$filename = $row['filename'];
print "<li><a href=\"/sites/mysite.com/files/$filename\" class=\"01\"><img src=\"/sites/mysite.com/files/$filename\" /></a></li>\n";
}
}
print "</ul>\n";
?>
The above code works fine, but I also want to add an image description inside this <li>:
print "<li><h1>$description</h1><a href=\"/sites/mysite.com/files/$filename\" class=\"01\"><img src=\"/sites/mysite.com/files/$filename\" /></a></li>\n";
So each image in a list item will also have a description.
The problem is that the description of the image is in a completely different table in the database: SELECT description from upload
So how do I make this happen for the description part. the filename php is working good.