monkeytooth Posted April 2, 2010 Share Posted April 2, 2010 is there anyway I can query any given table in my database, and output it in an array or something? Has anyone done this? Whether the table is empty or holds records. I need to some how query selected tables and just return the column names from it but not the actual results/records held within any of the tables queried. I'm not sure if this is possible, but then again thinking about it more so while I type, phpmyadmin does is.. but how.. It'd be nice for a simple full answer cause im super tired about to pass out, but if thats not acceptable by anyone ill just take ideas as to what I should do, and where I should look or read rather on how to do it. Link to comment https://forums.phpfreaks.com/topic/197345-php-mysql-query-yield-column-names/ Share on other sites More sharing options...
ScotDiddle Posted April 2, 2010 Share Posted April 2, 2010 monkeytooth, Try this: <?php Header("Cache-control: private, no-cache"); Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); Header("Pragma: no-cache"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><head> <head> <?php //include file to connect to database require_once( 'DB_Connect.php' ); $tableName = 'Some_Table_Name'; $SQL = 'select column_name from information_schema.columns where table_name=\''.$tableName.'\';' ; $result = mysql_query($SQL); if( !$result ) { //if there was a sql error echo mysql_error(); exit; } else { // otherwise get the result set $columnCount = (int)( mysql_num_rows( $result ) ); for( $i = 0; $i < $columnCount; $i++ ) { //print the results of the search $columnName = mysql_result( $result, $i, 'column_name' ); echo $columnName . "<br /><br/> \n"; } } ?> </body> </html> Scot L. Diddle, Richmond VA Link to comment https://forums.phpfreaks.com/topic/197345-php-mysql-query-yield-column-names/#findComment-1035881 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.