dongming5444 2014-11-05 00:43
浏览 30
已采纳

Mysqli语句返回错误

I am trying to return the data that is true from my database using this mysqli statement

$resulttwo = mysqli_query($link, "
SELECT 
*
FROM
Events 
WHERE 
time >= '%$lasttime%'");

The variable "lasttime" is an float of a really high value. The numbers in the database are all below below this number. However, when I use this statement, it returns all rows in the database. I do not understand why using this comparison yields incorrect results. Is there something that I am missing?

  • 写回答

1条回答 默认 最新

  • dslijian2015 2014-11-05 01:56
    关注

    '%$lasttime%' is a string, that equates to zero when used in a numeric comparison. time may be a string column, as you say, but gets successfully cast numeric when you use >=. if $lasttime equaled 12345 and $time equaled 54321, then the comparison is 54321 >= '%12345%' which equates to 54321 >= 0, as '%12345%' doesn't get converted to an int.

    To test:

    select '%12345%' = 0, '12345' = 0
    

    returns TRUE (because that's a non-numeric string, whose value is 0) and FALSE (because that string can be converted to 12,345, and not equal to 0).

    I have no idea why you want to use wildcards in this query.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作