peuge Posted March 26, 2008 Share Posted March 26, 2008 Hi, I am using PHP5 and am wandering how I can echo all the tables and their field names in a selected database. $tables = array(); $rows = mysql_query("SHOW TABLES FROM $dbinfo"); while ($row = mysql_fetch_array($rows)) { $tables[] = $row[0]; } print_r($tables); The above just shows the tables in the database but not the fields in that table. Could anyone please tell me how I would go about doing this. Thanks Peuge Link to comment https://forums.phpfreaks.com/topic/97936-show-table-and-table-values-from-a-database/ Share on other sites More sharing options...
lordfrikk Posted March 26, 2008 Share Posted March 26, 2008 DESCRIBE $tablename or SHOW COLUMNS FROM $tablename. http://dev.mysql.com/doc/refman/5.0/en/describe.html http://dev.mysql.com/doc/refman/5.0/en/show-columns.html Link to comment https://forums.phpfreaks.com/topic/97936-show-table-and-table-values-from-a-database/#findComment-501048 Share on other sites More sharing options...
peuge Posted March 26, 2008 Author Share Posted March 26, 2008 Thanks! What mysql_fetch would I use in the while loop? Link to comment https://forums.phpfreaks.com/topic/97936-show-table-and-table-values-from-a-database/#findComment-501050 Share on other sites More sharing options...
lordfrikk Posted March 26, 2008 Share Posted March 26, 2008 <?php $result = mysql_query("SHOW COLUMNS FROM sometable"); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; } if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { print_r($row); } } ?> Link to comment https://forums.phpfreaks.com/topic/97936-show-table-and-table-values-from-a-database/#findComment-501059 Share on other sites More sharing options...
peuge Posted March 26, 2008 Author Share Posted March 26, 2008 Thanks. It works. Much appreciated. Link to comment https://forums.phpfreaks.com/topic/97936-show-table-and-table-values-from-a-database/#findComment-501066 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.