dongpao9437 2018-04-26 11:28
浏览 72
已采纳

从mysql中选择时间戳的范围在phpmyadmin中工作,但不在codeigniter中

I have read almost every question i have found here and did not get a solution for my problem.

thing is that my query works in phpMyAdmin search but it does not work in codeigniter query.

here is code From phpMyAdmin that works:

SELECT * FROM `pozvani_brojevi` 
WHERE `vrijeme_poziva` 
BETWEEN '2018-04-05 00:00:00' AND '2018-04-26 00:00:00' 
ORDER BY `vrijeme_poziva` DESC

and here is code from codeigniter that don't work:

$this->db->select('*');
$this->db->from('pozvani_brojevi');
$this->db->where('user_id', $user_id);
$this->db->where("'vrijeme_poziva', BETWEEN 2018-04-05 00:00:00 AND 2018-04-26 00:00:00");
$result = $this->db->get();
$pozvani = $result->result_array();
return $pozvani;    

note that i have changed code in various ways and always got same result

$this->db->where("vrijeme_poziva, BETWEEN 2018-04-05 00:00:00 AND 2018-04-26 00:00:00");

$this->db->where("vrijeme_poziva BETWEEN 2018-04-05 00:00:00 AND 2018-04-26 00:00:00");

and i get this error message:

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 '00:00:00 AND 2018-04-26 00:00:00' at line 4

SELECT * FROM `pozvani_brojevi` WHERE `user_id` IS NULL AND `vrijeme_poziva` BETWEEN `2018-04-05` `00:00:00` AND 2018-04-26 00:00:00
  • 写回答

3条回答 默认 最新

  • douzhi9478 2018-04-26 11:33
    关注

    Use Null as second and FALSE as third parameter as below:

    $this->db->where(' vrijeme_poziva BETWEEN 2018-04-05 00:00:00 AND 2018-04-26 00:00:00', NULL, FALSE);
    

    Another Option that you can use >= and <= in two separate where condition as below:

    $this->db->where('vrijeme_poziva >=', '2018-04-05 00:00:00');
    $this->db->where('vrijeme_poziva <=', '2018-04-26 23:59:59');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里