Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP根据时间获取正确的数据库记录_Php_Mysql_Codeigniter - Fatal编程技术网

PHP根据时间获取正确的数据库记录

PHP根据时间获取正确的数据库记录,php,mysql,codeigniter,Php,Mysql,Codeigniter,请尝试使用单选按钮从数据库中获取任务,但没有获得正确的记录,我使用了Codeigniter 这是我的代码: switch(strtolower($this->input->post('tasksfilter'))){ case "overdue": $query = array("task_accomplish_date <=" => time()); break; case "today": $query

请尝试使用单选按钮从数据库中获取任务,但没有获得正确的记录,我使用了
Codeigniter

这是我的代码:

switch(strtolower($this->input->post('tasksfilter'))){
    case "overdue":
        $query = array("task_accomplish_date <=" => time());
        break;
    case "today":
        $query = array("task_accomplish_date <=" => strtotime("today midnight"));
        break;
    case "tomorrow":
        $query = array("task_accomplish_date <=" => strtotime("tomorrow midnight"));
        break;
    }
$this->data['result'] = $this->crud->read_where("tasks", $query)->result();
注意*
task\u complete\u date
是一个
varchar
字段,包含
timestamp

提前感谢您的帮助

问题是您总是在寻找小于或等于特定日期的日期。因为“今天”总是少于“明天”,所以你的答案中自然也会有“今天”

如果
task\u completion\u date
列中的值始终为所讨论日期的午夜,则可以使用相等运算符。如果使用午夜以外的“一天中的某个时间”,那么我将不得不修改答案。以下假设值始终为午夜

这个答案还假设您只想要“明天”,而不想要任何以后的日子,即后天

$findDay = strtotime("today");
switch (strtolower($this->input->post('tasksfilter')))
{
    case "overdue":
        $findDay -=  86400; //subtract one days worth of seconds
        break;
    case "tomorrow":
        $findDay += 86400; //add a day to "today"
        break;
}
$query = array("task_accomplish_date == " => $findDay);
$this->data['result'] = $this->crud->read_where("tasks", $query)->result();

显示你的
read_,其中
方法也可以,你可以仔细检查你是否有任何错误?没有,例如,当我单击“明天广播”时,我得到了今天的结果,因为我的输入字段名称是正确的,我确信,问题只是$querymake sure with
echo$this->input->post('tasksfilter')中的算法有问题是否给出了正确的字符串
$findDay = strtotime("today");
switch (strtolower($this->input->post('tasksfilter')))
{
    case "overdue":
        $findDay -=  86400; //subtract one days worth of seconds
        break;
    case "tomorrow":
        $findDay += 86400; //add a day to "today"
        break;
}
$query = array("task_accomplish_date == " => $findDay);
$this->data['result'] = $this->crud->read_where("tasks", $query)->result();