Current location: Hot Scripts Forums » Programming Languages » PHP » filling HTML table with MySQL data


filling HTML table with MySQL data

Reply
  #1 (permalink)  
Old 05-02-04, 12:25 PM
warrerj warrerj is offline
New Member
 
Join Date: May 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy filling HTML table with MySQL data

Sorry if this seems really simple to you but I'm very new to php.

I've got a html table with table headers (5) set up on a page. I want to show the results of a database search on the from, creating a new row for each record returned.

I'm ok with the simple html syntax and have got the php to print the results row by row with a horizontal line between them but can't seem to get the results in a table. I the code I tried was :

...
db connection and query etc.

echo(" <tr> ");
echo(" <td width="20%"> ");
echo($row["customerID"]);
echo(" </td> ");
echo(" <td width="20%"> ");
echo($row["surname"]);
echo(" </td> ");
echo(" <td width="20%"> ");
echo($row["forenames"]);
echo(" </td> ");
echo(" <td width="20%"> ");
echo($row["street"]);
echo(" </td> ");
echo(" <td width="20%"> ");
echo($row["post_code"]);
echo(" </td> ");
echo(" </tr> ");
...
</table>

Can anyone please help ?

Thanks
Reply With Quote
  #2 (permalink)  
Old 05-02-04, 06:03 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
did you have the table's tag started?
I mean did you print any <table border="0" width=" ... > before you start the tables <tr>s and <td>s ?
because in your code you don't seem to have it !

also you don't need all this echos !! just one is enough !
PHP will ignore any spaces or newlines in your code ..
PHP Code:

//we start the table here

echo'<table border="0" width="100%">';

//then we loop through results
while ($row mysql_fetch_assoc($fetch)) {
echo
'
  <tr>
    <td width="20%">'
.$row["customerID"].'</td>
    <td width="20%">'
.$row["surname"].'</td>
    <td width="20%">'
.$row["forenames"].'</td>
    <td width="20%">'
.$row["street"].'</td>
    <td width="20%">'
.$row["post_code"].'</td>
  </tr>'
;
}

//close table here..
echo'</table>'
now, doesn't this look cleaner !!
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]

Last edited by NeverMind; 05-02-04 at 06:14 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie MySQL fccolon PHP 2 03-16-04 10:54 AM
Collecting html form data and sending it to a sql table crobinson ASP 3 01-04-04 09:16 PM
help plz: format retrieved Mysql data in HTML with PHP paulj000 PHP 2 10-19-03 08:03 PM
moving data from table to table ..please help! geneane ASP 2 09-22-03 07:02 PM


All times are GMT -5. The time now is 10:31 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.