problems on summing for a range of data in the model query, codeigniter 3 - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12) +--- Thread: problems on summing for a range of data in the model query, codeigniter 3 (/showthread.php?tid=79370) |
problems on summing for a range of data in the model query, codeigniter 3 - enricof - 06-05-2021 Hi! I find myself in the need to add the hours extracted only on a range of dates (only the months taken individually of the year), in the traditional formula of mysql this thing I can do through the query, for example let's take the month of May: SELECT SUM (table_time) AS total FROM table_name WHERE table_date> = '2021-05-01' AND table_date <= '2021-05-31'; my problem is the following, in active record on codeigniter 3 how should i structure the model query? I was thinking something like: $ this-> db-> select ("SUM (hours) AS total"); $ this-> db-> from ("uw_planner"); $ this-> db-> where ('data', '2021-01-01> = 2021-01-31'); $ query1 = $ this-> db-> get (); if ($ query1-> num_rows ()> 0) { $ res = $ query1-> row_array (); return $ res ['total']; } return 0.00; } but with $ this-> db-> where ('data', '2021-05-01> = 2021-05-31'); can't I get anything? How can I solve? Basically I can't tell the query with active record just extract the hours on the dates going from the beginning of the month to the end of the month, thanks in advance for any suggestions ths Enricof RE: problems on summing for a range of data in the model query, codeigniter 3 - InsiteFX - 06-06-2021 Not tested but should work for you. PHP Code: $this-> db-> where ('data =', '2021-01-01'); RE: problems on summing for a range of data in the model query, codeigniter 3 - paliz - 06-06-2021 For sake of god migrate to ci4 Why you are wast of precious time demoed ci3 My precious my ci4 For sake of god migrate to ci4 |