gpt4 book ai didi

php - 比较两个时间戳 Codeigniter

转载 作者:行者123 更新时间:2023-11-29 23:28:27 26 4
gpt4 key购买 nike

我正在尝试计算用户在 Codeigniter 中收到的通知数量。我正在比较每个用户行中保存的时间戳(记录他们上次检查通知页面的时间)和为每个通知添加的时间。但是我收到数据库错误:

A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '10:17:00' at line 5

SELECT * FROM (`notifications`) WHERE `user_id` = '1' AND `instigator_id` != '1' AND added <= 2014-11-04 10:17:00

文件名:/Users/true/Documents/Site/models/private/notifications_model.php

行号:152

通知 Controller 看起来像这样

$data["user"] = $CI->Profile_model->get_public_profile_id($logged_user);
$count = $CI->notifications_model->get_notifications_count($data["user"][0]["notes_check"]);

型号:

public function get_notifications_count($time){


$this->db->from($this->notifications_table);
$this->db->where('user_id', $this->session->userdata("id", 0));
$this->db->where('instigator_id !=', $this->session->userdata("id", 0));
$this->db->where('added <= '.$time, '', false);
$query = $this->db->get();
$results = $query->result_array();

return count($results);
}

最佳答案

您的日期/时间值是字符串。由于它们周围没有 '-引号,MySQL 会看到:

added <= 2014-11-04 10:17:00
^^^^^^^^^^---mathematical subtraction = 1999
^^^^^^^^^--illegal unknown field/table name

应该是

added <= '2014-11-04 10:17:00'

注意引号。

关于php - 比较两个时间戳 Codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26767852/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com