title: mysql select all, group by orderid
body: <p>I was wondering if anyone could help me with selecting information from my table, but grouping the results depending on the order id. I'm sure this is quite simple, but I can't seem to get the code working.</p>
  
  <p>Here's my attempt - which is only showing 1 result, instead of 6:</p>
  
  <ul>
  <li>4 results with orderid 55542</li>
  <li>2 results with orderid 55543</li>
  </ul>
  
  <p>SQL:</p>
  
  <pre><code>SELECT *
  FROM #__users_orders
  WHERE userid = 22 
  GROUP BY orderid 
  ORDER BY date DESC
  </code></pre>
  
  <p>Any help would be appreciated :)</p>
  
  <p>EDIT:</p>
  
  <p>I'd like to acheive this (or something similar)</p>
  
  <pre><code>Array[55542]
  (
      [0] =&gt; stdClass Object
          (
              [id] =&gt; 6
              [userid] =&gt; 66
              [orderid] =&gt; 55542
              [date] =&gt; 2011-08-05 16:30:24
              [code] =&gt; 121021
              [title] =&gt; 7 STAR CHICKEN A/KING 71198 1.3KG
              [units] =&gt; 2
              [ctns] =&gt; 
          )
  
      [1] =&gt; stdClass Object
          (
              [id] =&gt; 1
              [userid] =&gt; 66
              [orderid] =&gt; 55542
              [date] =&gt; 2011-08-05 16:06:12
              [code] =&gt; 302371
              [title] =&gt;  ANCHOVY FILL 730GM
              [units] =&gt; 2
              [ctns] =&gt; 
          )
  
      [2] =&gt; stdClass Object
          (
              [id] =&gt; 6
              [userid] =&gt; 66
              [orderid] =&gt; 55542
              [date] =&gt; 2011-08-05 16:30:24
              [code] =&gt; 121021
              [title] =&gt; 7 STAR CHICKEN A/KING 71198 1.3KG
              [units] =&gt; 2
              [ctns] =&gt; 
          )
  
      [3] =&gt; stdClass Object
          (
              [id] =&gt; 1
              [userid] =&gt; 66
              [orderid] =&gt; 55542
              [date] =&gt; 2011-08-05 16:06:12
              [code] =&gt; 302371
              [title] =&gt;  ANCHOVY FILL 730GM
              [units] =&gt; 2
              [ctns] =&gt; 
          )
  
  )
  
  Array[55543]
  (
      [0] =&gt; stdClass Object
          (
              [id] =&gt; 6
              [userid] =&gt; 66
              [orderid] =&gt; 55543
              [date] =&gt; 2011-08-05 16:30:24
              [code] =&gt; 121021
              [title] =&gt; 7 STAR CHICKEN A/KING 71198 1.3KG
              [units] =&gt; 2
              [ctns] =&gt; 
          )
  
      [1] =&gt; stdClass Object
          (
              [id] =&gt; 1
              [userid] =&gt; 66
              [orderid] =&gt; 55543
              [date] =&gt; 2011-08-05 16:06:12
              [code] =&gt; 302371
              [title] =&gt;  ANCHOVY FILL 730GM
              [units] =&gt; 2
              [ctns] =&gt; 
          )
  
  )
  </code></pre>