Have sqlite table:
orderitems
-id
-item_id
-quantity
I need to count each item_id That is not a problem:
$this->db->query("SELECT item_id,COUNT(item_id)
FROM sh_orderitems
GROUP by item_id
ORDER by COUNT(item_id) DESC LIMIT 5")->fetchAll();
Result is:
0 =>
array (size=4)
'item_id' => string '38' (length=2)
0 => string '38' (length=2)
'COUNT(item_id)' => string '3' (length=1)
1 => string '3' (length=1)
But that is not good solution, 'cause: quantity dos't counted. Need something like SELECT item_id,COUNT(item_id)*quantity
Aucun commentaire:
Enregistrer un commentaire