943,667 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 13210
  • PHP RSS
Oct 28th, 2008
0

PHP Tables

Expand Post »
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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
gpdrums is offline Offline
36 posts
since Sep 2007
Oct 29th, 2008
0

Re: PHP Tables

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.
Reputation Points: 232
Solved Threads: 137
Practically a Master Poster
buddylee17 is offline Offline
665 posts
since Nov 2007
Oct 29th, 2008
0

Re: PHP 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:
php Syntax (Toggle Plain Text)
  1. echo '<table>';
  2. while ($row = mysql_fetch_array($result)){
  3. //loop through the rows
  4. echo '<tr>';
  5. foreach ($row as $element){
  6. //loop through elements (ie td's)
  7. echo "<td>$element</td>";
  8. }
  9. echo '</tr>';
  10. }
  11. echo '</table>';
foreach documentation
Reputation Points: 20
Solved Threads: 13
Junior Poster in Training
humbug is offline Offline
93 posts
since Oct 2005
Oct 29th, 2008
0

Re: PHP Tables

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.
Reputation Points: 15
Solved Threads: 5
Junior Poster in Training
TopDogger is offline Offline
87 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Chmod with a timer
Next Thread in PHP Forum Timeline: oscommerce





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC