开发者

How to put the a mysql column into an array with php? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplet开发者_如何学Goe, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜