Click to See Complete Forum and Search --> : how return a field name with the value in a mysql query?


jason213123
February 15th, 2009, 10:44 AM
hi,
i need get the name of the field by a query
for example

if a do this:

$res = mysql_query( "select * from total )
$v1=mysql_fetch_row_name($res);
while($v1=mysql_fetch_row($res)) {

echo $v1[0]; // return the value of field number 0

}

but i need to know also this:


echo "the field name xxx have this record ". $v1[0];

in vb we have the objects that return the name and the value and all information of the field but how can i see this in php?
thanks a lot for your help
:)

PeejAvery
February 15th, 2009, 05:36 PM
Well, rather than using mysql_fetch_row(), you could use mysql_fetch_object() or mysql_fetch_assoc(). Then, you could just acquire the keys. Or, you can also use a SQL query to return the fields.

SHOW COLUMNS FROM tablename