gpt4 book ai didi

php - 如何使用 php 从 mysql 数据库获取多行

转载 作者:行者123 更新时间:2023-11-29 06:32:43 25 4
gpt4 key购买 nike

我的数据库中有一个表,其中包含多个带有 ID 的字段。我想获取 ID=1 的所有行(例如 ID=1 在表中有 3 行)。我编写了一个查询来从数据库中获取 ID=1 的行,但该查询仅获取第一行。我想获取 ID=1 的所有行。

如何获取 ID=1 的所有行?

我的 PHP 代码:

 $conn = mysqli_connect('localhost', 'root', '', 'win');
$query = "SELECT * FROM lights WHERE id='1'";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($result);
print_r($row);
?>```

最佳答案

您需要循环 mysqli_fetch_assoc($result)

while ($row = mysqli_fetch_assoc($result)) { //Goes through each row of the query
print_r($row); //A row from the table
}

来源:mysqli_result

关于php - 如何使用 php 从 mysql 数据库获取多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55424234/

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