我的MySql查询出了什么问题?

时间:2010-03-09 02:38:57

标签: php mysql

这是我使用PHP进行mysql的查询 这是查询行

<?php
$query = "SELECT * FROM node WHERE type = 'student_report' AND uid = '{$uid}' LIMIT 1 ORDER BY created DESC";
?>

我收到以下错误

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 'ORDER BY created DESC' at line 1

4 个答案:

答案 0 :(得分:3)

你需要最后一个限制条款。

答案 1 :(得分:1)

您不需要$uid

周围的花括号

如果这不能解决问题,请尝试在LIMIT子句之后添加order by子句,这是推荐的方法。来源Mysql select syntax

答案 2 :(得分:1)

您的查询应该是:

$query = "SELECT * FROM node WHERE type = 'student_report' AND uid = $uid ORDER BY created DESC LIMIT 1";

答案 3 :(得分:0)

打印整个sql查询($query),不仅$uid还有LIMIT之后的order by子句