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>'; } } } Quote Link to comment 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 />"; } } Quote Link to comment Share on other sites More sharing options...
PeggyBuckham Posted December 15, 2010 Author Share Posted December 15, 2010 Thank-you!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.