gpt4 book ai didi

php - mysqli_fetch_array 只返回一个结果

转载 作者:行者123 更新时间:2023-11-29 04:20:15 25 4
gpt4 key购买 nike

我正在尝试使用以下代码(在 $host 等中使用适当的值)对小型 mysql 数据库进行非常非常简单的查询:

$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);

如您所见,我以人类可读的方式打印出结果,产生:

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

该专栏中有一些示例大学,所以我不确定我做错了什么。

最佳答案

mysqli_fetch_array 每次调用时都通过指针工作

想象一下

$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

要以您希望的方式实际显示数据,我建议您执行以下操作

$rows = array();
$result = mysqli_query($connection, "select university from universities_alpha");
while($row = mysqli_fetch_array($result)) {
$rows[] = $row;
}

print_r($rows);

关于php - mysqli_fetch_array 只返回一个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26415596/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com