简体   繁体   English

mysqli查询[活动记录Codeigniter]

[英]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 日期为Y|m|d格式,时间为24 hrs格式, status= 0表示未完成

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 current date 2015|9|19 and time 10:05:3现在,我希望获取当前日期和时间用户未完成的所有任务,以便结果看起来像下面这样,总未完成任务为好

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. 请建议同时使用mysqliCodeIgniter's Active-records查询。
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: 对于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>";

        }

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

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