且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获得使用PHP列的所有值?

更新时间:2023-02-23 13:07:08


  

请注意,这个答案已经过时了! MySQL扩展不再提供开箱即用的PHP7的。如果要使用旧版本的MySQL功能PHP7,的你将不得不从PECL编译分机/ MySQL的。见其他答案更多的现有解决方案。


块引用>

这会工作,在这里看到更多的文档:
http://php.net/manual/en/function.mysql-fetch -array.php

  $结果= mysql_query(选择客户名称);
$ storeArray =阵列();
而($行= mysql_fetch_array($结果,MYSQL_ASSOC)){
    $ storeArray [] = $行['姓名'];
}
//现在$ storeArray将拥有所有的名字。

I've been searching for this everywhere, but still can't find a solution: How do I get all the values from a mySQL column and store them in an array?

For eg: Table Name: Customers Column names: ID, Name # of rows: 5

I want to get an array of all the 5 names in this table. How do I go about doing that? I am using PHP, and I was trying to just:

SELECT names FROM Customers

and then use the

mysql_fetch_array

PHP function to store those values in an array.

Any ideas on this?

Thanks in advance!

Note that this answer is outdated! The mysql extension is no longer available out of the box as of PHP7. If you want to use the old mysql functions in PHP7, you will have to compile ext/mysql from PECL. See the other answers for more current solutions.


This would work, see more documentation here : http://php.net/manual/en/function.mysql-fetch-array.php

$result = mysql_query("SELECT names FROM Customers");
$storeArray = Array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $storeArray[] =  $row['names'];  
}
// now $storeArray will have all the names.