所以这段代码不起作用,我无法弄明白。
$productid = (isset($_REQUEST['productId'])) ? $_REQUEST['productId'] : '';
$query = "SELECT * FROM products WHERE productId = '$productid' ORDER BY rand() limit 3";
答案 0 :(得分:0)
也许试试:
$productid = (isset($_REQUEST['productId'])) ? $_REQUEST['productId'] : '';
if ($productid != ''){
$query = "SELECT * FROM products WHERE productId = '$productid' ORDER BY rand() limit 3";
} else {
$query = "SELECT * FROM products ORDER BY rand() limit 3";
}
如果productId没有结束,这应该返回所有产品。