我目前正在做一个电子商务系统。我想监控那个月有多少人购买了特定产品。例如,我正在销售耳机,5人在1月,2月份购买了耳机,依此类推。
问题:是否可以将mm存储在我的表格中?
注意:我在html中使用了datepicker(html中datepicker的格式为yyyy-mm-dd)
CONTROLLER
$data['products'] = $this->CrudModel->count_all('products','date');
print_r($data['products']);die;
MODEL
public function count_all($table,$date)
{
$this->db->select('product_name');
$this->db->from($table);
$this->db->where(array('date' => '$date' )); // What should I put here? So that I can fetch the date starting January until December
$num_results = $this->db->count_all_results();
}
我的产品表格的列
'event_id' 'full_name' 'email' 'date' 'contact'
答案 0 :(得分:0)
尝试以下代码。
$this->db->where('date >=', $start_date);
$this->db->where('date <=', $end_date);
或者您也可以尝试
$where = "DATE(date) BETWEEN '2017-01-01' AND '2017-02-01'";
答案 1 :(得分:0)
您可以使用下面的分组
public function count_all($table,$date)
{
$this->db->select('product_name');
$this->db->from($table);
$this->db->where('date >=', $start_date);
$this->db->where('date <=', $end_date);
$this->db->order_by('date','desc');
$this->db->group_by('MONTH(date), YEAR(date)');
$num_results = $this->db->count_all_results();
}