EricSanchez3099
07-19-2004, 11:35 PM
I'm trying to make a page that selects the image names from mysql table, and displays them in an html table. I want the table to have 3 columns wide on each row, and as many rows as it needs to fulfill how many images there are. I tried this, and other ways, but couldn't figure it out:
$sql="SELECT * FROM kenpo ";
$result=mysql_query($sql,$db);
$num=mysql_num_rows($result);
$cur = 1;
$images = array();
while ($row = mysql_fetch_assoc($result)) {
$images[] = $row['thumbpath'];
}
echo "<table width='90%' border='1' cellspacing='2' cellpadding='2'><tr>";
for ($i = 0, $n = count($images); $i < $n; $i = $i + 3) {
echo "<td><img src='./dbpics/$images[$i]' height='125' width='125'><td>";
if ($i + 1 < $n) {
echo "<td><img src='./dbpics/" . $images[$i + 1] . "' height='125' width='125'></td>";
}
if ($i + 2 < $n) {
echo "<td><img src='./dbpics/" . $images[$i + 2] . "' height='125' width='125'></td><br>";
}
echo "</tr></table>";
}
?>
So if there were 9 images (or image name & paths) in the database, it would show 3 rows of 3 columns per row. If it had 10 images, it would show 4 rows -- of which the 4th row only has 1 image. Is there a way to do this?
Any help is appreciated!
Thanks
$sql="SELECT * FROM kenpo ";
$result=mysql_query($sql,$db);
$num=mysql_num_rows($result);
$cur = 1;
$images = array();
while ($row = mysql_fetch_assoc($result)) {
$images[] = $row['thumbpath'];
}
echo "<table width='90%' border='1' cellspacing='2' cellpadding='2'><tr>";
for ($i = 0, $n = count($images); $i < $n; $i = $i + 3) {
echo "<td><img src='./dbpics/$images[$i]' height='125' width='125'><td>";
if ($i + 1 < $n) {
echo "<td><img src='./dbpics/" . $images[$i + 1] . "' height='125' width='125'></td>";
}
if ($i + 2 < $n) {
echo "<td><img src='./dbpics/" . $images[$i + 2] . "' height='125' width='125'></td><br>";
}
echo "</tr></table>";
}
?>
So if there were 9 images (or image name & paths) in the database, it would show 3 rows of 3 columns per row. If it had 10 images, it would show 4 rows -- of which the 4th row only has 1 image. Is there a way to do this?
Any help is appreciated!
Thanks