如何在 where 条件下使用 ORDER BY RAND()

how to use ORDER BY RAND() with where condition

我想使用带条件的 ORDER BY RAND() 显示我的产品

这是我的查询

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

我知道这个没有 where 条件的正常工作查询[=​​12=]

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

但我想使用 where 条件

提前致谢

只需简单地使用 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";

对不起我的英语。