Skip to content
Advertisement

Create PHP array from MySQL column

mysql_fetch_array will give me an array of a fetched row. What’s the best way generate an array from the values of all rows in one column?

Advertisement

Answer

you could loop through the array, and create a new one, like so:

$column = array();

while($row = mysql_fetch_array($info)){
    $column[] = $row[$key];
//Edited - added semicolon at the End of line.1st and 4th(prev) line

}
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement