0

它向我展示了:

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 'WHERE company='ABC' AND branch='26' AND owner IS NULL' at line 1

$sql="SELECT * FROM spr ORDER BY id WHERE company='$_SESSION[company]' AND branch='$_SESSION[branch]' AND owner IS NULL";

我看不出我的查询出了什么问题。请大侠帮忙...

4

4 回答 4

5

order by子句必须在子句之后where

于 2012-12-20T15:53:25.770 回答
1

试试这个,它ORDER BY应该是语句末尾的子句

$sql="SELECT * FROM spr 
      WHERE company='".$_SESSION[company]."' 
      AND branch='".$_SESSION[branch]."' 
      AND owner IS NULL ORDER BY id";
于 2012-12-20T15:53:58.057 回答
0
$sql="SELECT * FROM spr WHERE company='$_SESSION[company]' AND branch='$_SESSION[branch]' AND owner IS NULL ORDER BY id";
于 2012-12-20T15:54:03.593 回答
0

{}在 PHP 中使用双引号时,需要用大括号括住数组值和对象属性。

$sql="SELECT * FROM spr 
      WHERE company='{$_SESSION[company]}' 
        AND branch='{$_SESSION[branch]}' AND owner IS NULL
      ORDER BY id ";

你的ORDER BY条款需要放在最后。

于 2012-12-20T15:55:22.650 回答