jeff5656 Posted August 23, 2010 Share Posted August 23, 2010 Lets say I want to get the name of the first field in a table (or the second) and assign it to a variable. i.e., if the first fieldname in a table is called "record_number", I would want: $first = "record_number"; Here's what I was able to come up with so far but not sure what to do next: $sql = "SELECT * FROM $tbl "; $result = mysql_query($sql) or die("Query failed : " . mysql_error()); $line = mysql_fetch_array($result, MYSQL_ASSOC); Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 23, 2010 Share Posted August 23, 2010 Given your current code, try: $first = key($line); Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 23, 2010 Share Posted August 23, 2010 Oh, and assuming you want others later I would use this to get them all into an array: $fields = array_keys($line); Quote Link to comment Share on other sites More sharing options...
jeff5656 Posted August 23, 2010 Author Share Posted August 23, 2010 That did it - thanks! 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.