I know there is mysql_fetch_assoc which puts all data from a row into an array. Is there something equivalent for putting all data in a column into an array? e.g. a list of title ID's?
3 Answers
GROUP_CONCAT and explode() is probably what you're looking for as it can get everything in one row. You can group all of the values with a comma using GROUP_CONCAT and then populate the array using explode().
Your SQL would contain this:
SELECT GROUP_CONCAT(column_name SEPARATOR ',') AS col
And your PHP would create the array like this (after performing the query):
$col_array = explode(',' $row['col']);
Comments
If you're able to use external libraries, it may be worth looking into the Zend database library. Zend_Db provides a function called fetchCol where it will return an array without having to write any additional code.