PeggyBuckham Posted December 14, 2010 Share Posted December 14, 2010 I want to retrieve the field names from a database with the associated values. I know how to retrieve the values but haven’t figured out how to get the field names. Here is the code I use to get the values. $sql='SELECT * FROM table WHERE table_id =' .$id; $result = mysql_query($sql,$db) or die(mysql_error(). "<br/>SQL: $sql"); $row = mysql_fetch_array($result); if($row){ foreach ($row as $key => $value){ if(!empty($value)){ print '<p>'.$value.'</p>'; } } } Link to comment https://forums.phpfreaks.com/topic/221686-retrieving-field-names-and-values-from-database/ Share on other sites More sharing options...
BlueSkyIS Posted December 14, 2010 Share Posted December 14, 2010 $sql='SELECT * FROM table WHERE table_id =' .$id; $result = mysql_query($sql,$db) or die(mysql_error(). "<br/>SQL: $sql"); while ($row = mysql_fetch_assoc($result)) { foreach ($row AS $col=>$value) { echo "Column: $col - Value: $value <br />"; } } Link to comment https://forums.phpfreaks.com/topic/221686-retrieving-field-names-and-values-from-database/#findComment-1147431 Share on other sites More sharing options...
PeggyBuckham Posted December 15, 2010 Author Share Posted December 15, 2010 Thank-you!! Link to comment https://forums.phpfreaks.com/topic/221686-retrieving-field-names-and-values-from-database/#findComment-1147448 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.