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...
jdavidbakr Posted December 14, 2010 Share Posted December 14, 2010 $key should contain the field names in your code. Quote Link to comment Share on other sites More sharing options...
schilly Posted December 14, 2010 Share Posted December 14, 2010 if($row){ foreach ($row as $key => $value){ if(!empty($value)){ print '<p>'.$key."=".$value.'</p>'; } } } 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.