while循環不顯示從數據庫收集的所有數據..只顯示頁面中最後一個收集的項目。而不是全部展示。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();
?>
我是stucked這裏PLZ讓我離開我從這裏走出
刪除'LIMIT 6' ,'LIMIT 6'表示只有最後6行 – Shehary
@Shehary這將解決什麼。現在有6個結果,只顯示1個結果會有什麼區別? – RiggsFolly
@Shehary。我試過這個..仍然沒有工作。 –