eugene2009 Posted October 28, 2009 Share Posted October 28, 2009 Hey, is it possible to list all the table names in a database on an html page? For example: Database Name: Cars Table Names: -BMW -Mercedes -Volkswagen -Ford -Volvo How do I have it generate that list automatically if I add new tables later on? Quote Link to comment https://forums.phpfreaks.com/topic/179368-solved-listing-table-names-please-help/ Share on other sites More sharing options...
cags Posted October 28, 2009 Share Posted October 28, 2009 Once the database is selected... $result = mysql_query("SHOW TABLES"); echo '<ul>'; while($row = mysql_fetch_array($result)) { echo '<li>' . $row[0] . '</li>'; } echo '</ul>'; Quote Link to comment https://forums.phpfreaks.com/topic/179368-solved-listing-table-names-please-help/#findComment-946448 Share on other sites More sharing options...
eugene2009 Posted October 28, 2009 Author Share Posted October 28, 2009 THANK YOU!!! Quote Link to comment https://forums.phpfreaks.com/topic/179368-solved-listing-table-names-please-help/#findComment-946457 Share on other sites More sharing options...
eugene2009 Posted October 28, 2009 Author Share Posted October 28, 2009 is it possible to show tables from 2 databases in one list.. how would i make this work???? mysql_select_db ([color=red][b]test, blog[/b][/color]); $result = mysql_query("SHOW TABLES"); echo '<ul>'; while($row = mysql_fetch_array($result)) { echo '<li>' . $row[0] . '</li>'; } echo '</ul>'; Quote Link to comment https://forums.phpfreaks.com/topic/179368-solved-listing-table-names-please-help/#findComment-946464 Share on other sites More sharing options...
eugene2009 Posted October 28, 2009 Author Share Posted October 28, 2009 sorrryy exclude the font formatting.. mysql_select_db (test, blog); $result = mysql_query("SHOW TABLES"); echo '<ul>'; while($row = mysql_fetch_array($result)) { echo '<li>' . $row[0] . '</li>'; } echo '</ul>'; Quote Link to comment https://forums.phpfreaks.com/topic/179368-solved-listing-table-names-please-help/#findComment-946467 Share on other sites More sharing options...
cags Posted October 28, 2009 Share Posted October 28, 2009 I believe the SHOW TABLES has a FROM syntax, not tested it but I'd try something like... mysql_query("SHOW TABLES FROM db1, db2"); Quote Link to comment https://forums.phpfreaks.com/topic/179368-solved-listing-table-names-please-help/#findComment-946472 Share on other sites More sharing options...
eugene2009 Posted October 28, 2009 Author Share Posted October 28, 2009 doesnt work.. im pretty sure there needs to be somthing in this line: mysql_select_db (test, blog); thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/179368-solved-listing-table-names-please-help/#findComment-946478 Share on other sites More sharing options...
cags Posted October 28, 2009 Share Posted October 28, 2009 I don't believe you can select multiple tables like that, but you should be able to do this... echo '<ul>'; $result = mysql_query("SHOW TABLES FROM table1"); while($row = mysql_fetch_array($result)) { echo '<li>' . $row[0] . '</li>'; } $result = mysql_query("SHOW TABLES FROM table2"); while($row = mysql_fetch_array($result)) { echo '<li>' . $row[0] . '</li>'; } echo '</ul>'; Quote Link to comment https://forums.phpfreaks.com/topic/179368-solved-listing-table-names-please-help/#findComment-946503 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.