SQL语法错误按DESC排序

时间:2015-08-06 02:08:35

标签: mysql mysqli

我正在运行MYSQL 5.5版,我收到以下错误。我已尝试将LIMIT 1添加到最后,删除ORDER BY DESC指定按DATE(submit_date)排序...但仍然收到相同的错误。

您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在第1行的“ORDER BY DESC”附近使用正确的语法

function getApplicationStatus($userId) {
    $SQLString = "SELECT status, DATE(submit_date) FROM ". $GLOBALS['TABLES']['APPLICATION'] ." WHERE fk_userid = $userId ORDER BY DESC";
    $results = mysqli_query($GLOBALS['DB']['CONNECT'], $SQLString) or die("Error: ".mysqli_error($GLOBALS['DB']['CONNECT']));
    $data = mysqli_fetch_array($results);
    return $data['status'];
}

3 个答案:

答案 0 :(得分:3)

您在订单中缺少一个字段:ORDER BY DESC

添加字段:ORDER BY someField DESC或删除ORDER BY DESC文字。

答案 1 :(得分:0)

您应该指明column_name。

SQL ORDER BY语法:

SELECT column_name, column_name
 FROM table_name
 ORDER BY column_name ASC|DESC, column_name ASC|DESC;

来自:http://www.w3schools.com/sql/sql_orderby.asp

答案 2 :(得分:0)

试试这个。     $ SQLString =" SELECT状态,DATE(submit_date)FROM"。 $ GLOBALS [' TABLES'] [' APPLICATION']。"在哪里fk_userid = $ userId ORDER BY' submit_date' DESC&#34 ;;