2016-04-21 87 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