Page 1 of 1

Column names of certain fields

Posted: Mon Feb 27, 2006 9:39 pm
by jpaw
Is there an easy way to display the column name(s) from a mysql result? For example, if I have an SQL statement like

Code: Select all

SELECT id,name FROM `table`
and assuming that I do not know the SQL statement beforehand, is there a way to find the column name and display it?

I know

Code: Select all

SHOW FIELDS FROM
will show all of the fields in a table, but I just need to display the ones used in the query.

Sorry if what I'm trying to say isn't clear, but that's the best way I can think of stating it right now.

Thanks in advance.

Posted: Mon Feb 27, 2006 10:04 pm
by Benjamin

Code: Select all

$Data = mysql_fetch_assoc(mysql_query("select * from table",$LinkID));
Returns an array with the field names as keys and the corresponding values.

Posted: Mon Feb 27, 2006 11:10 pm
by josh
To add onto that

Code: Select all

print_r(array_keys($Data));