Php 如何在where条件下使用ORDER BY RAND()
我想使用ORDER BY RAND()和where条件显示我的产品Php 如何在where条件下使用ORDER BY RAND(),php,mysql,cakephp-2.0,Php,Mysql,Cakephp 2.0,我想使用ORDER BY RAND()和where条件显示我的产品 $qry="select * from product_tbls ORDER BY RAND() LIMIT 0,6;"; 这是我的问题 $qry="select * from product_tbls where category_tbls_id=".$data["0"]["product_tbls"]["category_tbls_id"]; 我知道没有where条件的正常工作查询 $qry="select * from
$qry="select * from product_tbls ORDER BY RAND() LIMIT 0,6;";
这是我的问题
$qry="select * from product_tbls where category_tbls_id=".$data["0"]["product_tbls"]["category_tbls_id"];
我知道没有where条件的正常工作查询
$qry="select * from product_tbls ORDER BY RAND() LIMIT 0,6;";
但我想用where条件
$qry="select * from product_tbls ORDER BY RAND() LIMIT 0,6;";
Thanx提前。只需使用
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;"
如果这是您要问的问题:您应该在ORDER BY rand()之前使用“WHERE” 例如:
$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";
对不起,我说的是英语。订购与此无关。语法是
select。。。从…起哪里下单
,无论您是以何种方式下单。您遇到的问题是什么?看在上帝的份上。如果不起作用,试试看manual@RiggsFolly对不起,伙计,没人想直接来问我,我在试着。但是我不明白。当使用ORDER BY RAND()
时,当您在表中获得几十行以上的数据时,当您的查询性能绝对下降时,请不要感到惊讶。意外的“””检查更新的答案。感谢你的帮助,我错过了“
.thanx,但是,只有一点点”this@Vky没有问题。很高兴你修好了。