...

View Full Version : PHP MySQL result into Array



dstu
05-18-2011, 05:34 AM
Hello,

I would like to "SELECT * FROM 'table'" and put the result into an array, but the array keys should represent the table columns (assuming I don't know them in advance).

I see many examples for code that extracts the data into arrays in which I have to put the keys manually, but I'm looking for something automatic.

For example, if the table is something like this:
ID Name Address
-- ----- --------
1 John New York
2 Terry Miami

The array should be:
[ID]=>1 [Name]=>John [Address]=> New York
[ID]=>2 [Name]=>Terry [Address]=> Miami

What should I do?

Thanks,

David

Inigoesdr
05-18-2011, 06:29 AM
Check out mysql_fetch_assoc() (http://php.net/mysql_fetch_assoc).

dstu
05-19-2011, 11:40 AM
Check out mysql_fetch_assoc() (http://php.net/mysql_fetch_assoc).

Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum