gpt4 book ai didi

php - 如何回显整个表格?现在我只得到最后一行

转载 作者:行者123 更新时间:2023-11-29 13:23:53 24 4
gpt4 key购买 nike

我现在有这段代码,我只获取最后两行,但我需要使用 html 获取数据库中的尽可能多的行。预先感谢您

      //We include the includes.php, which contains our db connection data.
include("includes.php");
//dbCon(); references the db connection data in includes.php - in other words we call a function.
dbCon();
$query = "SELECT * FROM product WHERE categoryid = 1;";
$result = mysqli_query($dbc,$query) or die('Error querying database.');
if (mysqli_num_rows($result) == NULL) {
mysqli_close($dbc);header("Location:index.php?l=f");exit();
}

while ($row = mysqli_fetch_assoc($result)){
$name = $row['name'];
$price = $row['price'];
}

echo "<input type='checkbox' name='name' value='name'>".$name."</br>";
echo "Price: "." "."<strong>".$price."</strong></br>";

最佳答案

将 echo 移至循环内部

while ($row = mysqli_fetch_assoc($result)){
$name = $row['name'];
$price = $row['price'];
echo "<input type='checkbox' name='name' value='name'>".$name."</br>";
echo "Price: "." "."<strong>".$price."</strong></br>";

}

关于php - 如何回显整个表格?现在我只得到最后一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20399434/

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