Hi All:

I'm connecting to a db to populate a table. My code loops through the db without errors. The problem is in Firefox, my rows of data display as individual tables. Everything works perfect in IE. Any ideas what I'm missing? The table population code basically looks like this:

echo "
} echo ">";

Also, if I place the ">" inside the curly bracket to close the table tag, IE displays each row as a table. So, echoing the ">" after the curly bracket fixed that problem. I've been coding for 9 hours, so I'm sure I'm just missing something obvious.

Thanks for the help!

9 Years
Discussion Span
Last Post by TopDogger

Keep the table element out of the loop. As long as <table> and </table> aren't being repeated in the loop, your not going to have multiple tables.


What buddylee said. What does the source to your page look like? It's probably not correct at all but IE happens to display it correctly.

You need something like this:

echo '<table>';
while ($row = mysql_fetch_array($result)){
  //loop through the rows
  echo '<tr>';
  foreach ($row as $element){
    //loop through elements (ie td's)
    echo "<td>$element</td>";
  echo '</tr>';
echo '</table>';

foreach documentation


humbug's code is correct.

The only reason that IE appeared to be displaying the table correctly is because the table code was invalid and the closing table tag was not being recognized. Each table was therefore not being completed.

Browsers correct a lot of coding problems while they attempt to render the page, which is probably why FireFox was displaying separate tables. It looks like you were creating separate tables and FireFox was correcting the coding error.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.