$query = "SELECT shop_id, article_id, design_id FROM shop_tshirts WHERE design_id = '$design'";
$zres = mysql_query($query) or die(mysql_error());
$total = mysql_num_rows($zres);
我使用此代码来获取使用特定$ design的产品数量。
是否可以仅按店铺数量计算产品数量?
此DB结构的示例:
shop_id / article_id / design_id
S01 / A01 / D01
S02 / A02 / D01
S03 / A03 / D01
S03 / A04 / D01
通常使用这种结构,我的代码的结果将是4 ...我想更改代码,因此结果将是3,因为D01在S03中被使用了两次,我想每个商店只计算一次
谢谢!
答案 0 :(得分:0)
SELECT distinct shop_id, article_id, design_id FROM shop_tshirts WHERE design_id = '$design'
答案 1 :(得分:0)
您必须使用SQL SELECT DISTINCT语句
$query = "SELECT DISTINCT shop_id, article_id, design_id FROM shop_tshirts WHERE design_id = '$design'";
答案 2 :(得分:0)
您需要唯一的shop_id值
您不需要article_id或design_id
$query = "SELECT DISTINCT shop_id FROM shop_tshirts WHERE design_id ='$design'";
$zres = mysql_query($query) or die(mysql_error());
$total = mysql_num_rows($zres);