2016-04-21 46 views
-1

我想在那里条件如何使用WHERE条件

这是我的查询

$qry="select * from product_tbls where category_tbls_id=".$data["0"]["product_tbls"]["category_tbls_id"]; 

我知道这正常显示使用ORDER我的产品BY RAND()使用ORDER BY RAND()工作查询,而我想用WHERE条件

where条件

$qry="select * from product_tbls ORDER BY RAND() LIMIT 0,6;"; 

Thanx提前。

+0

排序无关紧要。语法是'select ... from ... where ... order',无论您按照什么顺序排列。 –

+0

你遇到了什么问题? – urfusion

+0

对于heavyans而言。 **尝试**如果它不工作**看手册** – RiggsFolly

回答

0

如果这是你问:你应该使用 “WHERE” ORDER BY兰特()之前。

例子:

$qry="select * from product_tbls WHERE a = 'b' ORDER BY RAND() LIMIT 0,6;"; 

你忘了来连接查询的其余部分。

$qry="select * 
     from product_tbls 
     where category_tbls_id=".$data["0"]["product_tbls"]["category_tbls_id"]." 
     ORDER BY RAND() LIMIT 0,6"; 

对不起,我的英语。

+0

其工作thanx – Vky

0

只是简单的利用where条件与order by

$qry="SELECT * FROM product_tbls 
    WHERE category_tbls_id = '".$data["0"]["product_tbls"]["category_tbls_id"]."' 
    ORDER BY RAND() 
    LIMIT 0,6;" 
+0

意外'''' – Vky

+0

检查更新的答案。我错过了'''。 – urfusion

+0

thanx为你的帮助,但是,只是一点点“这个 – Vky