MySQL Table Names in PHP DropDown

Hi Chaps,

I’m trying to get a list of MySQL table names in a PHP/HTML Select List/Menu with the value of the Select Option being the table name.

I have this as a starting point, but can’t figure out how to get the values into the Select.

$result = mysql_query("SHOW TABLES FROM 'DATABASE'");

while($table = mysql_fetch_array($result))

Any help would be sweet. .

I would also be very careful about echoing table names, as it opens the door to people finding out your database schema, which adds to the possibility of injection.

I would use $table = fetch_row and $table[0]

I see what you’re trying to do. So basically SHOW TABLES will return the non-temporary tables for you.

So that you can see the results you can echo it out. I’ll use example_db as my database example.

$result = mysql_query("SHOW TABLES FROM example_db");

while($table = mysql_fetch_array($result))


  echo $table['Tables_in_example_db'];


Tables_in_* will depend on the database name.