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); Link to comment https://forums.phpfreaks.com/topic/211528-get-the-name-of-the-first-field-in-a-table/ 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); Link to comment https://forums.phpfreaks.com/topic/211528-get-the-name-of-the-first-field-in-a-table/#findComment-1102808 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); Link to comment https://forums.phpfreaks.com/topic/211528-get-the-name-of-the-first-field-in-a-table/#findComment-1102811 Share on other sites More sharing options...
jeff5656 Posted August 23, 2010 Author Share Posted August 23, 2010 That did it - thanks! Link to comment https://forums.phpfreaks.com/topic/211528-get-the-name-of-the-first-field-in-a-table/#findComment-1102815 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.