[英]Show products from a specific category in the product list
I just want to ask how do I show specific category only in a product list? 我只想问一下如何仅在产品列表中显示特定类别?
<?php
include "storescripts/connect_to_mysql.php";
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 15");
$productCount = mysql_num_rows($sql); // count the output amount
$i = 0;
$dynamicList = '<table border="1" bordercolor="#d6d6d6" cellpadding="10"
cellspacing="0" style="border-collapse:collapse;">';
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$brand = $row["brand"];
$product_name = $row["product_name"];
$pdetails = $row["pdetails"];
$details = $row["details"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
if ($i % 3 == 0) { // if $i is divisible by our target number (in this case "3")
$dynamicList .= '<tr><td><a href="product.php?id=' . $id . '" title="' . $pdetails . '"><img src="inventory_images/' . $id . '.jpg" height="280" border="0" ><br><br>' . $brand . '<br>' . $product_name . '</a></td>';
} else {
$dynamicList .= '<td><a href="product.php?id=' . $id . '" title="' . $pdetails . '"><img src="inventory_images/' . $id . '.jpg" height="280" border="0" ><br><br>' . $brand . '<br>' . $product_name . '</a></td>';
}
$i++;
}
$dynamicList .= '</tr></table>';
?>
The category that I want to show is $comment
with a value of Best Seller
. 我要显示的类别是$comment
,其值为Best Seller
。 I hope this is enough code to understand and help. 我希望这足以理解和帮助代码。
If you just want to show all best sellers then you can change the query 如果您只想显示所有畅销书,则可以更改查询
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 15");
to 至
$sql = mysql_query("SELECT * FROM products
where `comment` = 'Best Seller'
ORDER BY date_added DESC LIMIT 15");
The above will fetch all the best seller products. 以上将获取所有最畅销的产品。
You do not need to change anything in the PHP side, the query will sort for you !! 您不需要在PHP方面进行任何更改,查询将为您排序!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.