Jump to content

[SOLVED] printing out mysql table


kev wood

Recommended Posts

i have found this code and would like to know how i can get the column titles to show up at the top of the page.

 

$result = mysql_query( "SELECT * FROM merc_users" ) 
or die("SELECT Error: ".mysql_error()); 
$num_rows = mysql_num_rows($result); 
print "There are $num_rows records.<P>"; 
print "<table width=1000 height=400 border=1>\n"; 
while ($get_info = mysql_fetch_row($result)){ 
print "<tr>\n"; 
foreach ($get_info as $field) 
print "\t<td><font face=arial size=2/>$field</font></td>\n"; 
print "</tr>\n"; 
} 
print "</table>\n"; 

 

this code simply just prints out all the data without the titles to the columns

Link to comment
Share on other sites

thanks for the reply.  i used that function.  i has been having trouble with this site today keeps timing out when i try to load pages.  only just let me back in now.

 

i got all the names printed out for the titles of each column.

Link to comment
Share on other sites

You really shuldn't be using FONT tags any more, but here you go:

 

<?php

$result = mysql_query( "SELECT * FROM merc_users" ) 
         or die("SELECT Error: ".mysql_error()); 

print "There are " . mysql_num_rows($result) . " records.<P>"; 
print "<table width=\"1000\" height=\"400\" border=\"1\">\n"; 

$showHeaders = true;
while ($get_info = mysql_fetch_row($result)){ 

 //Show headers on 1st pass
 if ($showHeaders) {
   print "<tr>\n";
   foreach ($get_info as $header => $field)
     print "\t<th><font face=\"arial\" size=\"2\">$header</font></th>\n"; 
   print "</tr>\n";
   $showHeaders = false;
 }

 //Display the record data
 print "<tr>\n";
 foreach ($get_info as $field)
   print "\t<td><font face=\"arial\" size=\"2\">$field</font></td>\n"; 
 print "</tr>\n"; 
}

print "</table>\n"; 

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.