mysqli_fetch_array returning only one result(mysqli_fetch_array 只返回一个结果)
问题描述
我正在尝试使用以下代码(在 $host 中使用适当的值等)对小型 mysql 数据库进行非常非常简单的查询:
I'm trying to make a very, very simple query of a small mysql database, using the following code (with appropriate values in $host, etc.):
$result = mysqli_query($connection, "select university from universities_alpha");
$row = mysqli_fetch_array($result);
echo print_r($result);
echo '<br><br>';
echo print_r($row);
如您所见,我以人类可读的方式打印了结果,结果是:
As you can see, I printed out the results in a human-readable way, yielding:
mysqli_result Object ( [current_field] => 0 [field_count] => 1 [lengths] => Array ( [0] => 19 ) [num_rows] => 9 [type] => 0 ) 1
Array ( [0] => Arizona State Univ. [university] => Arizona State Univ. ) 1
该专栏中有一些示例大学,所以我不确定我做错了什么.
There are a few example universities in that column, so I'm not sure what I'm doing wrong.
推荐答案
mysqli_fetch_array 每次调用时都通过指针工作
mysqli_fetch_array works by pointers each time it's called
想象以下内容
$result = mysqli_query($connection, "select university from universities_alpha");
$row = mysqli_fetch_array($result); // this is the first row
$row = mysqli_fetch_array($result); // now it's the second row
$row = mysqli_fetch_array($result); // third row
要以您想要的方式实际显示数据,我建议您执行以下操作
To actually display the data the way you want it to, I suggest you do the following
$rows = array();
$result = mysqli_query($connection, "select university from universities_alpha");
while($row = mysqli_fetch_array($result)) {
$rows[] = $row;
}
print_r($rows);
这篇关于mysqli_fetch_array 只返回一个结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:mysqli_fetch_array 只返回一个结果


基础教程推荐
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01