gpt4 book ai didi

php - while 循环不显示从数据库收集的所有数据

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

while 循环不显示从数据库收集的所有数据.. 仅显示页面中最后收集的项目。而不是全部显示。

<?php 
include "connect_to_mysql.php";
$dynamicList = "";
$sql = mysql_query("SELECT * FROM product ORDER BY date DESC LIMIT 6");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {

//here is problem in this while loop.. dont know why it is not gathering all the items.


while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$product_name = $row["p_name"];
$price = $row["price"];
$date_added = strftime("%b %d, %Y", strtotime($row["date"]));
$details = $row["details"];
$category = $row["category"];
$subcategory = $row["sub_category"];
$category2 = $row["category2"];
$img_name = $row["img_name"];
$v_id = $row["v_id"];
$v_name = $row["v_name"];
$v_number = $row["v_number"];
$v_email = $row["v_email"];

$dynamicList="

<div id=\"single_product\" style=\"float:left; margin-left:20px; padding:10px;\">

<h3> $product_name </h3>
<h3> <img src='pics/$img_name' width='200px' height='200px'/> </h3>
<p><b><center> RUP $price </center></b></p>

<a href=\"details.php\" style=\"float:left; font-size:20px;\">Details</a>
<a href=\"cart.php\" style=\"float:right; font-size:20px;\">Add To Cart</a>

</div>
";

}
} else {
$dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>

我被困在这里了,请把我从这里救出来

最佳答案

您正在使用

$dynamicList="...

在你的循环中。我假设您稍后在代码中回应了 $dynamicList。您需要使用文本连接而不仅仅是 =

也一样

$dynamicList .= "...

它会在每次循环时添加到字符串而不是覆盖它

关于php - while 循环不显示从数据库收集的所有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32034871/

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