kool_samule Posted May 24, 2010 Share Posted May 24, 2010 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)) { $tables[]=$table; } Any help would be sweet. . Link to comment https://forums.phpfreaks.com/topic/202737-mysql-table-names-in-php-dropdown/ Share on other sites More sharing options...
marcus Posted May 24, 2010 Share Posted May 24, 2010 <?php $sql = "SHOW TABLES FROM database"; $res = mysql_query($sql) or die(mysql_error()); echo '<select name="tables">'; while($row = mysql_fetch_row($res)){ echo '<option value="'.$row[0].'">'.$row[0].'</option>'; } echo '</select>'; ?> Link to comment https://forums.phpfreaks.com/topic/202737-mysql-table-names-in-php-dropdown/#findComment-1062597 Share on other sites More sharing options...
kool_samule Posted May 24, 2010 Author Share Posted May 24, 2010 sweet, just what i'm after, i'm guessing that you could do something similar with COLUMNs as well as tables. . . . .many thanks! Link to comment https://forums.phpfreaks.com/topic/202737-mysql-table-names-in-php-dropdown/#findComment-1062601 Share on other sites More sharing options...
marcus Posted May 24, 2010 Share Posted May 24, 2010 Yep, but instead your query would look something like $sql = "SHOW COLUMNS FROM table_name"; Link to comment https://forums.phpfreaks.com/topic/202737-mysql-table-names-in-php-dropdown/#findComment-1062603 Share on other sites More sharing options...
kool_samule Posted May 24, 2010 Author Share Posted May 24, 2010 Got it, cheers dude Link to comment https://forums.phpfreaks.com/topic/202737-mysql-table-names-in-php-dropdown/#findComment-1062613 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.