stvalentine84 Posted November 6, 2008 Share Posted November 6, 2008 This code populates my listbox with the databases names that are on mySQL. However I am getting stuck when I try and make this poplulate my table names and not my database names. I was thinking about using mysql_select_db($_POST['Select_DB']); to select the database first then run through my script to grab the names but when i try and modify for table names I always get an empty listbox. anyhelp is appreciated, Thanks!! <html> <head><title>List DB</title></head> <body> <form method="POST" action="sub.php"><div><center><p>Select DataBase <input type="hidden" name="db_name" value="DB_names"> <SELECT NAME="Select_DB"> <?php $conn = @mysql_connect( 'localhost', 'user', 'pass' ) or die( mysql_errno().': '.mysql_error()); $result = mysql_list_dbs( $conn ); while( $row = mysql_fetch_object( $result ) ): echo "<option value=\"$row->Database\">$row->Database</option>"; endwhile; // Free resources / close MySQL Connection mysql_free_result( $result ); mysql_close( $conn ); ?> </select> <input type="submit" value="Submit"></center></div> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/131639-populate-listbox-with-database-table-names/ Share on other sites More sharing options...
fanfavorite Posted November 6, 2008 Share Posted November 6, 2008 Try mysql_list_tables($dbname); http://ca.php.net/mysql_list_tables. Link to comment https://forums.phpfreaks.com/topic/131639-populate-listbox-with-database-table-names/#findComment-683721 Share on other sites More sharing options...
stvalentine84 Posted November 6, 2008 Author Share Posted November 6, 2008 I believe my error is somewhere around my while loop <html> <head><title>List DB</title></head> <body> <form method="POST" action="sub.php"><div><center><p>Select Tables <input type="hidden" name="table_name" value="TABLE_names"> <SELECT NAME="Select_TABLE"> while( $row = mysql_fetch_object( $result ) ): echo "<option value=\"$row->Database\">$row->Database</option>"; endwhile; <?php $conn = @mysql_connect( 'localhost', 'user', 'pass' ) or die( mysql_errno().': '.mysql_error()); #Selects the database from the DB Listbox and uses this to list the tables $result = mysql_list_tables( $_POST['Select_DB'] ); while( $row = mysql_fetch_object( $result ) ): echo "<option value=\"$row->Database\">$row->Database</option>"; endwhile; // Free resources / close MySQL Connection mysql_free_result( $result ); mysql_close( $conn ); ?> </select> <input type="submit" value="Submit"></center></div> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/131639-populate-listbox-with-database-table-names/#findComment-683753 Share on other sites More sharing options...
NeTech-UK Posted November 6, 2008 Share Posted November 6, 2008 try changing the code of your while statement to one of the following... while($row = mysql_fetch_object($result)) { echo "<option value=\"$row->Database\">$row->Database</option>"; } or while($row = mysql_fetch_array($result)) { echo "<option value=\"$row->Database\">$row->Database</option>"; } Link to comment https://forums.phpfreaks.com/topic/131639-populate-listbox-with-database-table-names/#findComment-683757 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.