且构网

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

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

更新时间:2022-04-04 22:28:49

请注意,此答案已过时! 从 PHP7 开始,mysql 扩展不再开箱即用.如果你想在PHP7中使用旧的mysql函数,您必须从 PECL 编译 ext/mysql. 有关更多当前解决方案,请参阅其他答案.

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.

这行得通,请在此处查看更多文档: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.