Forum Moderators: coopster
I have a database table called photo which has various fields and one for filename.
The filename data is something like image1.jpg, image2.jpg...
Now in my php script, I am struggling to get the image to appear in the respective column of a table. Basically, I need the table field 'filename' to represent the filename of my images in the source directory and be printed in a column.
The query is
$SQL = "select * from photo";
if (!($photos = mysql_db_query($db,$SQL,$connection))) {
die (mysql_error());
the php code i'm using is:
while ($row = mysql_fetch_row($photos)) {
echo "<table width=\"100%\>";
echo "<tr><th>No</th>";
echo "<th>date</th>";
echo "<th>Filename</th>";
echo "<th>desc</th></tr>";
echo "<tr>";
foreach ($row as $key => $value) {
echo "<td width =\"25%\">";
print $value;
echo "</td>";
}
echo "</tr>";
echo "</table>";
}
Therefore, hopefully printing $value will print each row and hence each image in the right column. I believe i may need to store each filename in a <img> tag somewhere?
Any help would be appreciated,
Thanks
This might be closer to what you are wanting. I'm assuming that each $row result will contain the 4 values needed for each column.
while ($row = mysql_fetch_row($photos)) {
echo "<table width=\"100%\>";
echo "<tr><th>No</th>";
echo "<th>date</th>";
echo "<th>Filename</th>";
echo "<th>desc</th></tr>";
foreach ($row as $key => $value) {
if ($key == '0') echo "<tr><td width =\"25%\">$value</td>";
if ($key == '1') echo "<td width =\"25%\">$value</td>";
if ($key == '2') echo "<td width =\"25%\"><img src="images/myimages/" . $value . "></td>";
if ($key == '3') echo "<td width =\"25%\">$value</td></tr>";
}
}
echo "</table>";