locoblacbelt Posted May 2, 2010 Share Posted May 2, 2010 im making a web front-end for a database, and I want to make something that will essentially display all information for any query, just as the command line sql would. the following is my script, which is just supposed to make a heading row for a php table with the correct column names in it. <?php $query=$_POST['query']; $dbh = mysql_connect("localhost", "root"); mysql_select_db("mountainview3") or die(mysql_error()); $result=mysql_query("$query"); $i=0; $num_fields=mysql_num_fields($result); echo "<table border='1'>"; echo "<tr>"; while ($i<$num_fields) {$th=mysql_field_name($result, $i); echo"<th>$th</th>"; $i++; } echo "</td></tr>"; echo '</table>'; ?> I need it to process ANY sql query and output into a table, not just the one for a particular table. I get the following output for the example query select * from person_t; It displays the column names like this: unique_id last_name first_name , etc. instead of what i wanted, which was : unique_id | last_name | first_name, etc. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/200425-mysql-and-php-put-column-names-into-table-headers/ Share on other sites More sharing options...
Ken2k7 Posted May 2, 2010 Share Posted May 2, 2010 Hmm, maybe I should use that and run "DROP DATABASE mountainview3;" Quote Link to comment https://forums.phpfreaks.com/topic/200425-mysql-and-php-put-column-names-into-table-headers/#findComment-1051776 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.