How to put the a mysql column into an array with php? [closed]
I know you can put a row into an array but I am having trouble putting a column into an array. I have no code yet. I just wanna get the auto incrementing column "id" and put it into an array like like..
$array[0] = 1;
$array[1] = 2;
$array[2] = 3;
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$array[] = $row[0];
}
I am afraid there is no direct way to output a 1-dimensional array out of a mysql query.
The result set will always be a 2-dimensional array (# of results x # of columns) that you will need to transform into a 1-dimensional if you really have to.
I hope this will help you
Jerome Wagner
精彩评论