创建从MySQL列PHP数组 [英] Create PHP array from MySQL column

查看:114
本文介绍了创建从MySQL列PHP数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mysql_fetch_array 会给我一个提取行的数组。什么是最好的方法生成的所有行的值的数组中的一列?

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?

编辑:伟大的答案大量的。谢谢大家谁回答!我结束了类似于浓汤和GSTO提出了解决去。我答曰点GSTO因为他有那么点(只是帮忙的小家伙,没有任何个人)。

Lots of great answers. Thank you everyone who replied! I ended up going with a solution similar to what Gumbo and GSto suggested. I gave the answer points to GSto because he has less points (just helping out the little guy, nothing personal).

推荐答案

您可以遍历数组,并创建一个新的,就像这样:

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

}

这篇关于创建从MySQL列PHP数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆