Possible Duplicate:
mysql_fetch_array, mysql_fetch_assoc, mysql_fetch_object
I want a function which can return fields in the current row of a resultset into an associative array and moves the result pointer to the next row.
Confused between
mysql_fetch_row()
mysql_fetch_assoc()
mysql_fetch_array()
Which one should I use? Any help would be appreciated.
Thank you.
What is it?
You are looking for
mysql_fetch_assoc, as the name implies it will return an associative array (with the column names as keys and the values as the row values).What will the different functions return?
All of the mentioned functions will return an array, the differences between them is what values that are being used as keys in the returned object.
mysql_fetch_rowThis function will return a row where the values will come in the order as they are defined in the SQL query, and the keys will span from
0to one less than the number of columns selected.mysql_fetch_assocThis function will return a row as an associative array where the column names will be the keys storing corresponding value.
mysql_fetch_arrayThis function will actually return an array with both the contents of
mysql_fetch_rowandmysql_fetch_assocmerged into one. It will both have numeric and string keys which will let you access your data in whatever way you’d find easiest.It is recommended to use either
_assocor_rowthough.