mysqli查询[活动记录Codeigniter]

时间:2015-09-19 05:38:05

标签: php mysql codeigniter activerecord

  

我有一个时间表,如下所示

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

  

其中日期为 Y|m|d 格式且时间为24 hrs格式, status= 0 表示未完成

让我们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

  

请建议 mysqli CodeIgniter's Active-records 查询。

2 个答案:

答案 0 :(得分:1)

您应该尝试使用此活动记录:

$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();

和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";

答案 1 :(得分: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>";

        }