Pdo从2个表中选择连接

时间:2017-01-18 00:44:25

标签: php sql

所以我有一个查询,但我想添加一个功能,用户可以“暂停”

$stmt212 = $db->prepare('SELECT * 
FROM websites w
    LEFT JOIN users u ON u.username = w.owner
WHERE u.coins >= ? 
ORDER BY RAND() 
LIMIT 1');
$stmt212->execute( array('1') ) ;
$row212 = $stmt212->fetch();

这项工作但现在我需要从网站中选择live = 1已经在用户表中有超过1的硬币确实试过这个

$stmt212 = $db->prepare('SELECT * 
FROM websites WHERE live = ?
    LEFT JOIN users u ON u.username = w.owner
WHERE u.coins >= ? 
ORDER BY RAND() 
LIMIT 1');
$stmt212->execute( array('1','1') ) ;
$row212 = $stmt212->fetch();

但没有工作

1 个答案:

答案 0 :(得分:0)

试试这个:

$stmt212 = $db->prepare('SELECT * 
FROM websites
LEFT JOIN users u ON u.username = w.owner
WHERE u.coins >= ? 
AND live = ?
ORDER BY RAND() 
LIMIT 1');

$stmt212->execute( array('1','1') ) ;
$row212 = $stmt212->fetch();