title: selecting all orders for last 30 days, and counting how many per day
body: <p>I am trying to select <strong>all orders for last 30 days</strong> from one customer, so I need to have customer_id = "$customer_id" and <strong>count how many orders I have per each day</strong> for that one customer.</p>
  
  <p>I need to end up with array like this</p>
  
  <pre><code>Array ( 
    [1] =&gt; Array (
                   [orders] =&gt; 41
                   [date] =&gt; 2011-06-13 17:43:50 
                 )
    [2] =&gt; Array (
                   [orders] =&gt; 11
                   [date] =&gt; 2011-07-13 17:43:50  
                 )
    [4] =&gt; Array (
                   [orders] =&gt; 2
                   [date] =&gt; 2011-12-13 17:43:50  
                 )
  
    and so on... for 30 days, if some day I dont have any orders, I dont need array or [orders] = 0 ...
  
  }
  </code></pre>
  
  <p>I have table named "orders" with id, customer_id and date field.</p>
  
  <p>I found this questions <a href="https://stackoverflow.com/questions/1133109/sql-query-for-calculating-total-no-of-orders-per-day">SQL query for Calculating Total No. of Orders per Day?</a> but its not helping me, or I dont understand it very well, btw I am beginner. Thanks!</p>
  
  <p>p.s. what I managed to do, is to select all orders for last 30 days.</p>
  
  <pre><code>$this-&gt;db-&gt;query("SELECT * FROM orders WHERE customer_id=" . $customer['id'] . " AND date &gt; ADDDATE(CURDATE(), INTERVAL -30 DAY)")-&gt;result_array();
  </code></pre>