dongyi6269 2012-07-16 02:12
浏览 41
已采纳

在phpmyadmin中查询成功但在php中失败

I would like to ask about the query to select the last record in a table which can match a specific condition.

The following code can successfully execute and gives out the correct record in phpmyadmin

SELECT TYPE FROM log WHERE TechID=4 ORDER By LogTime DESC LIMIT 1

However,when I form the query in my php file and execute, it gives out error.

$query2 = "SELECT Type FROM Log WHERE TechID=".$row1['TechID']."ORDER BY LogTime DESC LIMIT 1"

here is the error message:

Error! 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 'BY LogTime DESC LIMIT 1' at line 1.

Can anyone tell me what is happening, myquery should be same as the one I use in the phpmyadmin

Below are the sample records I created to test my file.

LogID TechID ClientID SiteID Type     LogTime
1     2      5        1      Checkin  2012/07/04 09:00
2     4      5        1      Checkin  2012/07/04 09:00
3     2      5        1      Checkout 2012/07/04 10:00
  • 写回答

2条回答 默认 最新

  • dqkelut8423 2012-07-16 02:19
    关注

    I'd put a space before the order statement.

    " ORDER"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

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