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条)

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)