我有一个查询,它从表中选择随机行,并试图选择 id 以及另外三行,但是当我包括id
被选中时,它给了我错误。如果我删除id
查询工作正常。我需要它的原因id
是因为我需要它通过 url 传递到第二页。我错过了什么?
Call to a member function execute() on a non-object
查询:
$stmt = $mydb->prepare("SELECT id, title, price, image_one
FROM products AS r1 JOIN
(SELECT (RAND() *
(SELECT MAX(id)
FROM products )) AS id)
AS r2
WHERE r1.id >= r2.id and title != ''
ORDER BY r1.id ASC
LIMIT 1 ");
$stmt->execute();