简体   繁体   English

Codeigniter动态日期范围

[英]Codeigniter dynamic date range

I was asked to create some reports using charts. 我被要求使用图表创建一些报告。 I'm started studying programming recently so I might be asking something kinda stupid, but I'm really struggling with this one. 我最近开始学习编程,所以我可能会问一些愚蠢的问题,但是我确实为此感到挣扎。 I was able to draw the charts using google charts and querying my db BUT I don't know how to implement a date range picker. 我能够使用Google图表绘制图表并查询数据库,但我不知道如何实现日期范围选择器。 Here is my model, well, one of them... 这是我的模特,其中一个...

public function tester() {

 $this->db->where('type_id', 7);
 $this->db->where('entry_date >', '2016-05-11');
 $this->db->where('entry_date <', 'curdate()', FALSE);
 $this->db->select('first_name, last_name, count(type_id) AS totals');
 $this->db->from('entries');
 $this->db->join('users', 'users.user_id = entries.user_id');
 $this->db->group_by('entries.user_id');
 $this->db->order_by('totals', 'DESC');
 $this->db->limit(3);
 $query = $this->db->get();

 return $query->result();

}

Those dates in the where statements are there for testing purposes, it works just fine. where语句中的那些日期用于测试目的,效果很好。 Question is: How can I dynamically modify this query based on an start and end date selected by the user and redraw the chart? 问题是:如何根据用户选择的开始和结束日期动态修改此查询并重绘图表?

Thanks in advance 提前致谢

Usually with a start and end date range, you want to include the dates so i showed it as >= But you can also just make it > if you really need greater then etc. 通常使用开始和结束日期范围,您要包括日期,因此我将其显示为> =,但是如果确实需要更大的值,也可以将其显示为>等。

public function tester($startDate,$endDate) {

 $this->db->where('type_id', 7);
 $this->db->where('entry_date >=', $startDate);
 $this->db->where('entry_date <=', $endDate);
 $this->db->select('first_name, last_name, count(type_id) AS totals');
 $this->db->from('entries');
 $this->db->join('users', 'users.user_id = entries.user_id');
 $this->db->group_by('entries.user_id');
 $this->db->order_by('totals', 'DESC');
 $this->db->limit(3);
 $query = $this->db->get();

 return $query->result();

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM