Welcome Guest, Not a member yet? Register   Sign In
Display data week by week
#5

PHP Code:
$this->db->where('date_reg >='$week_start);
$this->db->where('date_reg <='$week_end); 
This would select a period of 8 days. You don't want to include next Sunday, use < instead of <=

There is a small problem in using:
PHP Code:
$start = new DateTime('last Sunday');
$end = new DateTime('next Sunday'); 
If you execute that code on a Sunday you select a period of 14 days, last Sunday is 7 days ago and next Sunday is in 7 days. In your case you only want the data from the current week so you would not notice it since no one could have a join date that lies in the future. But if you want to make your model function more flexible by adding a date (or year-weeknumber) as parameter for example to get the data from lets say last week you will run into this problem. So you can call getUserTotalByWeek('2016-33') and get the desired data.

I would also change:
PHP Code:
$this->db->select('*, COUNT(*) AS total'); 
To
PHP Code:
$this->db->select('date_reg, COUNT(date_reg) AS total'); 
It's bad practice to select everything when you only need use the data from 2 columns. Since your table is called 'user' I imagine it contains quite a few more columns then you are interested in at this function.
Reply


Messages In This Thread
Display data week by week - by wolfgang1983 - 08-22-2016, 07:14 PM
RE: Display data week by week - by PaulD - 08-22-2016, 07:42 PM
RE: Display data week by week - by wolfgang1983 - 08-22-2016, 11:55 PM
RE: Display data week by week - by PaulD - 08-23-2016, 10:05 AM
RE: Display data week by week - by Diederik - 08-25-2016, 05:15 AM
RE: Display data week by week - by salain - 08-26-2016, 02:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB