我正在尝试计算用户在Codeignter中收到的通知数量。我正在比较每个用户行中保存的时间戳,该时间戳记录了他们上次检查通知页面的时间以及为每个通知添加的时间。但是我收到了数据库错误:
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
通知控制器看起来像这样
$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);
}
答案 0 :(得分:0)
您的日期/时间值是字符串。由于你没有'
- 引用它们,MySQL正在看到这个:
added <= 2014-11-04 10:17:00
^^^^^^^^^^---mathematical subtraction = 1999
^^^^^^^^^--illegal unknown field/table name
应该是
added <= '2014-11-04 10:17:00'
注意引号。