以前の注文の情報を使用して、「ベストセラー」リストを作成したいと考えています。私が現在持っているのはこのようなものです。
Product Quantity
2227 30
1722 3
1851 7
2227 10
1722 4
1863 1
etc....
最初の列 (製品) は、各製品のデータベース内の一意の ID です。数量はもちろん何個売れたかです。各行は 1 つの注文です。したがって、ID2227
はこのリストに 2 回表示されます。
2227
このデータを並べ替えて、ID の合計販売回数を取得するにはどうすればよいですか?
現時点での私のPHPは次のとおりです。
$SQL_best = "SELECT c.company, co.id, cod.productId, cod.quantity
FROM customers c
LEFT JOIN customers_orders co ON c.id = co.custId
LEFT JOIN customers_orders_details cod ON co.id = cod.orderId
WHERE c.reseller =1
AND c.status != 99
AND c.id = ".$intCustomerId;
$result_best = $objDB->sqlExecute($SQL_best);
*some html code here*
<table style="margin:0px auto;">
<tr>
<th>Product</th>
<th>Quantity</th>
</tr>
<?php
while($obj_best = $objDB->getObject($result_best)) {
if ($obj_best->quantity > 0) { // don't include negatve quantaties (RMA's / refunds)
echo "<tr>";
echo "<td>".$obj_best->productId."</td>";
echo "<td>".$obj_best->quantity."</td>";
echo "</tr>";
}
}
?>
</table>
MySQL クエリ
だから私はすべての 's を一緒に追加する必要があり$obj_best->productId
ます。この場合、どうすればいいですか?または、クエリを編集する必要がありますか?