简体   繁体   中英

mysqli query [Active records Codeigniter]

i have a time-table as below

id task to-do-date to-do-time status 1 X 2015|9|19 21:10:1 0 2 Y 2015|9|19 09:05:3 0 3 Z 2015|9|17 08:12:3 0 4 A 2015|9|16 23:10:5 0

where date is in Y|m|d format and Time is in 24 hrs format , status= 0 means not Done

Lets current date 2015|9|19 and time 10:05:3 Now, I wish to fetch all the tasks which are not done by current date and time sofar, so that result could look like as bellow with total of not done tasks as well

id task to-do-date to-do-time status 2 Y 2015|9|19 09:05:3 0 3 Z 2015|9|17 08:12:3 0 4 A 2015|9|16 23:10:5 0 total Not-Done-taks =3

pls suggest be mysqli and CodeIgniter's Active-records query as-well for this.
Regards.....

You should try this for active records:

$this->db->select();
$this->db->from('your_table_name');
$this->db->where('to-do-date <= ',date('Y-m-d'));
$this->db->where('to-do-time <= ',date('H:i:s'));
$this->db->where('status',0);
return $this->db->get()->result();

and for mysqli:

$sql = "SELECT * FROM your_table_name WHERE to-do-date <= '".date('Y-m-d')."' AND to-do-time <= '".date('H:i:s')."' AND status = 0";
$this->db->select();
        $this->db->from('your_table_name');
        $this->db->where('to_do_date < ',date('Y-m-d'));
        $this->db->where('status','0');
        $this->db->or_where('to_do_date',date('Y-m-d'));
        $this->db->where('to_do_time < ',date('H:i:s'));
        $this->db->where('status',0);           
        $skipped = $this->db->get()->result_array();
        foreach ($skipped as $skp) {
            echo $skp['task'], $skp['to_do_date'],$skp['to_do_time'],$skp['status'], "</br>";

        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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