Jump to content

Listing Tables in a Drop Down Box?


Deanznet

Recommended Posts

Help list the Mysql Tables in a drop down box?  :facewall:

 

Select Category

<?

$sql = "SHOW TABLES FROM $db_name";
$result = mysql_query($sql);

if (!$result) {
    echo "DB Error, could not list tables\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}


  while ($row= mysql_fetch_row($result))
{
echo "<select name=Field>";

echo "<option value={$row[0]}>";
echo "<option value={$row[0]}>";

echo mysql_table_name($result, $i);
}
echo "</select></form>"; 
?>

 

I know the code is really messed up.. Can someone help.

Link to comment
https://forums.phpfreaks.com/topic/169823-listing-tables-in-a-drop-down-box/
Share on other sites

<?php
$sql = "SHOW TABLES FROM $db_name";
$result = mysql_query($sql);

if (!$result) {
    echo "DB Error, could not list tables\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}

echo "<select name=Field>";

while ($row= mysql_fetch_row($result)) {

echo "<option value={$row[0]}>{$row[0]}</option>";

}
echo "</select>";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.