title: How can I make a best-sellers list?
body: <p>I want to make a "best sellers" list using information from previous orders. What I currently have is something like this;</p>
  
  <pre><code>Product Quantity
  2227    30
  1722    3
  1851    7
  2227    10
  1722    4
  1863    1
  etc....
  </code></pre>
  
  <p>The first column (product) is the unique ID in the database for each product. The quantity is of course how many items have been sold. Each row is for one order. So the ID <code>2227</code> appears two times on this list.</p>
  
  <p>How can I sort this data so that I get a total of how many times ID <code>2227</code> is sold? </p>
  
  <p>My PHP at the moment is:</p>
  
  <pre><code>$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-&gt;sqlExecute($SQL_best);
  
  *some html code here*
  
  &lt;table style="margin:0px auto;"&gt;
  &lt;tr&gt;
      &lt;th&gt;Product&lt;/th&gt;
      &lt;th&gt;Quantity&lt;/th&gt;
  &lt;/tr&gt;
  &lt;?php
  while($obj_best = $objDB-&gt;getObject($result_best)) {
      if ($obj_best-&gt;quantity &gt; 0) { // don't include negatve quantaties (RMA's / refunds)
      echo "&lt;tr&gt;";
          echo "&lt;td&gt;".$obj_best-&gt;productId."&lt;/td&gt;";
          echo "&lt;td&gt;".$obj_best-&gt;quantity."&lt;/td&gt;";
      echo "&lt;/tr&gt;";
      }
  }
  ?&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>MySQL query</p>
  
  <p>So I need to add together all the <code>$obj_best-&gt;productId</code>´s. How do I do that in this case? Or should I be editing my query?</p>