kev wood Posted June 11, 2008 Share Posted June 11, 2008 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 Quote Link to comment Share on other sites More sharing options...
theinfamousmielie Posted June 11, 2008 Share Posted June 11, 2008 YO kev, long time no chat try using PHP's function: mysql_field_name() ?? Quote Link to comment Share on other sites More sharing options...
kev wood Posted June 11, 2008 Author Share Posted June 11, 2008 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. Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 11, 2008 Share Posted June 11, 2008 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"; ?> Quote Link to comment Share on other sites More sharing options...
theinfamousmielie Posted June 11, 2008 Share Posted June 11, 2008 Yeah, what he said *looks up* Quote Link to comment Share on other sites More sharing options...
kev wood Posted June 12, 2008 Author Share Posted June 12, 2008 thanks again for your replies i got it working and printing out everything i needed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.