0

我有这个查询调用:

$currplayer = 1;

$query = "SELECT f.fk_user_id2, u.username, u.profileimg FROM ".$prefix."_friends f 
                        INNER JOIN ".$prefix."_users u
                            ON f.fk_user_id2 = u.id     
                    WHERE f.fk_user_id1 = $currplayer ORDER BY u.username ASC";

if ($result = $mysqli->query($query)){
    while ($row1 = $result->fetch_assoc()){

        $friendid = $row1['fk_user_id2'];

        $sql = $mysqli->query("SELECT * FROM ".$prefix."_newversus WHERE fk_player=$currplayer AND fk_opponent=$friendid");
        $row = $sql->fetch_assoc();

我试图弄清楚如何将循环内的查询放入带有内部连接的第一个查询中,但无法弄清楚。

希望得到帮助并提前感谢:-)

4

1 回答 1

1

如果我正确理解了您,您想删除循环运行的查询并将其添加到主查询中。

尝试这个:

SELECT f.fk_user_id2, u.username, u.profileimg FROM ".$prefix."_friends f 
INNER JOIN ".$prefix."_users u ON f.fk_user_id2 = u.id 
INNER JOIN ".$prefix."_newversus n ON f.fk_user_id2 = n.fk_opponent 
WHERE f.fk_user_id1 = $currplayer AND
n.fk_player=$currplayer
ORDER BY u.username ASC;
于 2013-05-30T19:27:53.893 回答