php - selecting all orders for last 30 days, and counting how many per day -


i trying select all orders last 30 days 1 customer, need have customer_id = "$customer_id" , count how many orders have per each day 1 customer.

i need end array this

array (    [1] => array (                  [orders] => 41                  [date] => 2011-06-13 17:43:50                 )   [2] => array (                  [orders] => 11                  [date] => 2011-07-13 17:43:50                  )   [4] => array (                  [orders] => 2                  [date] => 2011-12-13 17:43:50                  )    , on... 30 days, if day dont have orders, dont need array or [orders] = 0 ...  } 

i have table named "orders" id, customer_id , date field.

i found questions sql query calculating total no. of orders per day? not helping me, or dont understand well, btw beginner. thanks!

p.s. managed do, select orders last 30 days.

$this->db->query("select * orders customer_id=" . $customer['id'] . " , date > adddate(curdate(), interval -30 day)")->result_array(); 

use mysql extract function fetch day date field , group results according this. haven't try following query should work:

select count(*) orders, date_field your_table customer_id=$my_cusotmer group extract(day date_field) 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -