Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在产品列表中显示特定类别的产品_Php_Mysql_E Commerce - Fatal编程技术网

Php 在产品列表中显示特定类别的产品

Php 在产品列表中显示特定类别的产品,php,mysql,e-commerce,Php,Mysql,E Commerce,我只是想问一下,如何仅在产品列表中显示特定类别 <?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;

我只是想问一下,如何仅在产品列表中显示特定类别

<?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>';

?>


我要显示的类别是
$comment
,其值为
畅销书
。我希望这些代码足够理解和帮助您。

如果您只想显示所有畅销书,那么您可以更改查询

$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 15");

以上内容将获得所有畅销产品


您不需要在PHP端更改任何内容,查询将为您排序

你是否有一个表列,其中包含关于畅销书的信息?是的@abhik chakraborty,我已将其添加到库存列表(phpmyadmin)中。我就是不知道怎么打电话。我的php表格中有一个产品列表,上面写着它们是最畅销的产品(id 10,产品名称棉籽,价格550,详细信息洁面乳,类别护肤品,子类别洁面乳,producttype痤疮预防评论畅销书,pdetails温柔如洁面乳),我知道了,那么你想在哪里展示呢?连同

'一起$品牌。”
“$产品名称。”我想替换dynamiclist的if语句:SHOW BEST-SELLER only我没有得到你可以使用下面的语句来检查它的畅销书是否像($row['comment']=='BEST-SELLER'){在这里添加你的代码}
$sql = mysql_query("SELECT * FROM products 
where `comment` = 'Best Seller'
ORDER BY date_added DESC LIMIT 15");