How to select multiple rows from mysql with one query and use them in php(如何使用一个查询从 mysql 中选择多行并在 php 中使用它们)
问题描述
我目前有一个如下图所示的数据库.
I currently have a database like the picture below.
其中有一个查询选择了 number1 等于 1 的行.当使用
Where there is a query that selects the rows with number1 equaling 1. When using
mysql_fetch_assoc()
在 php 中我只得到第一个有没有办法得到第二个?就像通过像
in php I am only given the first is there any way to get the second? Like through a dimesional array like
array['number2'][2]
或类似的东西
推荐答案
使用重复调用 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.
这篇关于如何使用一个查询从 mysql 中选择多行并在 php 中使用它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用一个查询从 mysql 中选择多行并在 php 中


- PHP foreach() 与数组中的数组? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01