Jump to content

Recommended Posts

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?

 

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.