我正在尝试像这样进行MySQL连接,
$q = $dbc -> prepare("SELECT m.* a.username FROM mailbox m JOIN accounts a (m.msgFrom = a.id) WHERE msgTo = ? AND sent = '0'");
$q -> execute(array($user['id']));
while ($msg = $q -> fetch(PDO::FETCH_ASSOC)) {
echo $msg['username'];
}
我想从表帐户中提取用户的用户名,而不是只显示表邮箱中的id,我让数组在查询中执行while循环,
这似乎不起作用,任何想法?
答案 0 :(得分:1)
你忘了加入条件中的on
试试这个:
SELECT m.*, a.username
FROM mailbox m JOIN accounts a on (m.msgFrom = a.id)
WHERE msgTo = ? AND sent = '0'