我有一个关于 mysqli_fetch_assoc 在 while 循环中的问题。
$query = "SELECT * FROM category ";
$result = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($result))
{
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
echo $cat_id . " " . $cat_title ."<br>";
}
那么,如何
$row = mysqli_fetch_assoc($result)
工作?所以它从
$results
一次循环一行并将该信息存储在 $row
中直到没有行返回?还有这个
mysqli_fetch_assoc($result)
在while循环迭代中是这个“数组(它从$result获得的一些行)”?$row = mysqli_fetch_assoc($result)
与 $row = array(all rows from $result that are gathered by mysqli_fetch_assoc)
相同?这意味着
$row
实际上是一个数组,每次循环时,信息都不会被 new 覆盖,而是被添加?
最佳答案
使用 mysqli_fetch_assoc()
时函数,PHP 将数据库中的数据放入关联数组中。然后,您可以从循环内的数组中提取数据。
由于没有增量告诉循环何时停止,while 循环会处理这个问题。所以你可以这样读:
而mysqli_fetch_assoc()
有更多记录,继续循环。当它用完时,停止。
关于php - mysqli_fetch_assoc 函数是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48053811/