My goal here is to set a variable to a field name from a mysql query. Some pseudo code below
1. $query = "SELECT firstName, lastName FROM users WHERE userName = 'mhopkins321';"
2. $result = mysql_query($result);
3. $while($row = mysql_fetch_assoc($result)){
4. $column1 = name_of_column($row['firstName']);
5. }
6. echo $column1
//Would return the string
firstName
obviously line 4 being the real pseudo part
Is this what you’re after?
Or just use
$columnand$valuehow you like inside theforeachloop.Or do you want specifically the first column, which can be accessed with
reset($row); $first_key = key($row);?