且构网

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

如何使用一个查询从 mysql 中选择多行并在 php 中使用它们

更新时间:2023-09-02 10:37:28

使用重复调用 mysql_fetch_assoc.它记录在 PHP 手册中.

Use repeated calls to mysql_fetch_assoc. It's documented right in the PHP manual.

http://php.net/manual/function.mysql-fetch-assoc.php

// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
//       then create $userid, $fullname, and $userstatus
while ($row = mysql_fetch_assoc($result)) {
    echo $row["userid"];
    echo $row["fullname"];
    echo $row["userstatus"];
}

如果需要,您可以使用它来构建多维数组,以便在脚本的其他部分使用.

If you need to, you can use this to build up a multidimensional array for consumption in other parts of your script.