2017-09-26 98 views
0

我正在使用查询获取json结果。它的工作正常,但现在我只想在表格引用qu_status = 1的地方取得结果。但我无法使其工作。没有检查上述条件我工作的查询是像下面Myqli查询条件

$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; 

但是我在这个错误的地方,所以我不能得到任何结果。让我知道如果有人能纠正我。由于

+0

where子句应该来内后加入条款和条款 – Manav

+0

@Manav由于订单之前,其工作的罚款:) – Priya

回答

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; 
+0

由于其工作的罚款与你的答案先生:) – Priya

0

尽量把后面的加入where条件。 也用您定义的别名q作为您的条件的前缀。

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