Myqli查询条件

时间:2017-09-26 14:07:54

标签: php mysql mysqli

我正在使用查询来获取json结果。它的工作正常,但现在我只想在表引号中获取结果qu_status = 1。但我无法使其发挥作用。我没有检查上述条件的工作查询如下所示

$sql = "SELECT q.*,c.au_picture as picture FROM tbl_quotes q INNER JOIN tbl_category c ON q.qu_author=c._auid Order By q.".$orde." Desc LIMIT ".$limit." OFFSET ".$offset;

我试图像下面那样使用它

$sql = "SELECT q.*,c.au_picture as picture FROM tbl_quotes where qu_status=1 q INNER JOIN tbl_category c ON q.qu_author=c._auid Order By q.".$orde." Desc LIMIT ".$limit." OFFSET ".$offset;

但我在这方面错了,所以我无法得到任何结果。如果有人能纠正我,请告诉我。感谢

2 个答案:

答案 0 :(得分:1)

where子句必须在连接之后

$sql = "SELECT q.*,c.au_picture as picture 
      FROM tbl_quotes  q
      INNER JOIN tbl_category c ON q.qu_author=c._auid 
      where q.qu_status=1  
      Order By q.".$orde." Desc LIMIT ".$limit." OFFSET ".$offset;

或者你可以直接联系避免在哪里

$sql = "SELECT q.*,c.au_picture as picture 
       FROM tbl_quotes q
       INNER JOIN tbl_category c ON q.qu_author=c._auid and q.qu_status=1  

  Order By q.".$orde." Desc LIMIT ".$limit." OFFSET ".$offset;

答案 1 :(得分:0)

尝试将where条件放在连接后面。 同时在条件前加上您定义的别名q

... where q.qu_status = 1 ...