lonewolf217 Posted August 25, 2008 Share Posted August 25, 2008 Not sure if this is possible or not. I am trying to consolidate code over several pages, all of which have similar queries where they gather data from a database and then output it to a table. The main reason right now why they are on separate pages is because the column headers for each of the tables is different, so i was wondering if there was any way i could programmatically get the name of the column in SQL to display ? Link to comment https://forums.phpfreaks.com/topic/121259-solved-get-the-name-of-the-column-from-a-sql-database/ Share on other sites More sharing options...
Psycho Posted August 25, 2008 Share Posted August 25, 2008 mysql_fetch_field() http://us.php.net/manual/en/function.mysql-fetch-field.php Link to comment https://forums.phpfreaks.com/topic/121259-solved-get-the-name-of-the-column-from-a-sql-database/#findComment-625142 Share on other sites More sharing options...
sasa Posted August 25, 2008 Share Posted August 25, 2008 or <?php $result = mysql_query('SELECT * FROM table_name'); $row = mysql_fetch_assoc($result); echo '<table><tr><td>'.implode('</td><td>', array_keys($row))."</td></tr>\n"; do { echo '<tr><td>'.implode('</td><td>',$row)."</td></tr>\n"; }while ($row = mysql_fetch_assoc($result)); echo "</table>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/121259-solved-get-the-name-of-the-column-from-a-sql-database/#findComment-625158 Share on other sites More sharing options...
lonewolf217 Posted August 25, 2008 Author Share Posted August 25, 2008 thanks, ill play around with it to see if i can get it to work out Link to comment https://forums.phpfreaks.com/topic/121259-solved-get-the-name-of-the-column-from-a-sql-database/#findComment-625167 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.