HTML Table in a "while' loop
Posted: Mon Jan 03, 2005 12:35 pm
I've been staring at this all morning and it's just sitting there laughing at me.
The idea is to access a number of items from a database and show the results in a table, 3 columns wide. The problem is that I can't seem to get the <tr> and </tr> in the right spot to start/end a new table row. Here's what I have:
Which results in the following HTML source:
I have a feeling I may be approaching this the wrong way.
The idea is to access a number of items from a database and show the results in a table, 3 columns wide. The problem is that I can't seem to get the <tr> and </tr> in the right spot to start/end a new table row. Here's what I have:
Code: Select all
print "<table cellpadding='2' cellspacing='2'>";
while (!$table_rows == "0"){
print "<tr>";
while ($display=mysql_fetch_array($result)) {
$count = "3";
if (!$count=="0") {
print "<td>";
print $display['filename'];
print "</td>";
$count--;
}
}
$table_rows--;
print "</tr>";
}
print "</table>";Code: Select all
<table cellpadding='2' cellspacing='2'><tr><td>003.jpg</td><td>004.jpg</td><td>007.jpg</td>
<td>008.jpg</td><td>009.jpg</td></tr><tr></tr></table>