【发布时间】:2015-11-09 04:10:50
【问题描述】:
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();
?>
我被困在这里,请把我从这里弄出来
【问题讨论】:
-
从查询中删除
LIMIT 6,LIMIT 6表示只有最后6行 -
@Shehary 那会解决什么问题。现在有 6 个结果,只显示 1 100 个结果会有什么不同????
-
@Shehary。我试过这个..还是不行。
-
@RiggsFolly 但如果想要获取所有记录,OP 仍然必须取消限制
-
我们必须假设 OP 只需要 6 行。但他确实希望看到所有 6 个,而不仅仅是最后一个
标签: php mysql loops while-loop nested-loops