PHP Tables

Reply

Join Date: Sep 2007
Posts: 36
Reputation: gpdrums is an unknown quantity at this point 
Solved Threads: 0
gpdrums gpdrums is offline Offline
Light Poster

PHP Tables

 
0
  #1
Oct 28th, 2008
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!
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: PHP Tables

 
0
  #2
Oct 29th, 2008
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.
Lost time is never found again.
- Benjamin Franklin
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 93
Reputation: humbug is an unknown quantity at this point 
Solved Threads: 13
humbug's Avatar
humbug humbug is offline Offline
Junior Poster in Training

Re: PHP Tables

 
0
  #3
Oct 29th, 2008
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:
  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
"If your not having fun, your doing something wrong." - Humbug
★ Did I help you out? Did I piss you off? Add to my reputation!
The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 87
Reputation: TopDogger is an unknown quantity at this point 
Solved Threads: 5
TopDogger's Avatar
TopDogger TopDogger is offline Offline
Junior Poster in Training

Re: PHP Tables

 
0
  #4
Oct 29th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2282 | Replies: 3
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC