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:

<?php
echo "
<table>
<tr>
<td>$col1</td>
<td>$col2</td>
<td>$col3</td>
</tr>
</table";
} 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!

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.