I'm 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>';
?>
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?
<?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>';
?>
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?