A
adz
Guest
Hi,
How can I retrieve the field names from a table in a MySQL database using PHP? I''ve used the SHOW COLUMNS from the table, but it returns all the field names plus their attributes (such as datatype) - I need to single out the field name alone.
I've also tried retrieving data from the information_schema table but that returns nothing, and I've tried the depreciated function mysql_list_field but that returns the same as SHOW COLUMNS.
Any help would be appreciated.
I'll post the code I have so far in additional info.
<?php
include('includes/dbconnect.php');
$category= mysql_real_escape_string($_GET["cat"]);
if (isset($category)){
$sql="SHOW COLUMNS FROM ". $category;
}else{
die('No Category Defined');
}
$result = mysql_query($sql) or die(mysql_error());
echo $sql;
echo "<form>";
while ($get_info = mysql_fetch_row($result)) {
foreach ($get_info as $column) {
echo '<select name="'.$column .'">';
echo '<option value="'. $column . '">'. $column .'</option>"';
echo '</select>';
echo '<br />';
}
}
echo "</form>";
include('includes/dbkill.php');
?>
How can I retrieve the field names from a table in a MySQL database using PHP? I''ve used the SHOW COLUMNS from the table, but it returns all the field names plus their attributes (such as datatype) - I need to single out the field name alone.
I've also tried retrieving data from the information_schema table but that returns nothing, and I've tried the depreciated function mysql_list_field but that returns the same as SHOW COLUMNS.
Any help would be appreciated.
I'll post the code I have so far in additional info.
<?php
include('includes/dbconnect.php');
$category= mysql_real_escape_string($_GET["cat"]);
if (isset($category)){
$sql="SHOW COLUMNS FROM ". $category;
}else{
die('No Category Defined');
}
$result = mysql_query($sql) or die(mysql_error());
echo $sql;
echo "<form>";
while ($get_info = mysql_fetch_row($result)) {
foreach ($get_info as $column) {
echo '<select name="'.$column .'">';
echo '<option value="'. $column . '">'. $column .'</option>"';
echo '</select>';
echo '<br />';
}
}
echo "</form>";
include('includes/dbkill.php');
?>