How to get the field name of a mysql table from a record in php?

  • Thread starter Thread starter GreenLeaf
  • Start date Start date
G

GreenLeaf

Guest
For example, lets say I had a table with 3 columns/field names:
Firstname Username Email

Now lets say the Username had the name "Maggy" in it. How can I using PHP determine the field name of its record. Or if the name "Molly" was in the database, how can I find what its field name is?
 
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("mydata");

$res = mysql_query('select * from users');

echo mysql_field_name($res, 0) . ("<br>");
echo mysql_field_name($res, 1) . ("<br>");
echo mysql_field_name($res, 2);
?>
 
Back
Top