Welcome Guest, Not a member yet? Register   Sign In
problems on summing for a range of data in the model query, codeigniter 3
#1

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
Reply
#2

Not tested but should work for you.
PHP Code:
$this-> db-> where ('data =''2021-01-01');
$this-> db-> where ('data <=''2021-01-31'); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 06-06-2021, 03:46 AM by paliz.)

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
Enlightenment  Is  Freedom
Reply




Theme © iAndrew 2016 - Forum software by © MyBB