mysql准备了fetch循环,不会使用连接为循环stmt

Thanks to anyone who is willing to help. I am trying to run a sql SELECT in a fetch loop of another select loop.

$mysqli = connect();
$stmt= $mysqli->prepare('SELECT lobby_id, user_penName, lobby_str 
                        FROM `tbl_lobbies` 
                            JOIN tbl_users ON tbl_lobbies.user_id = tbl_users.user_id 
                        WHERE lobby_active = ?');
$stmt->bind_param('i',$on);
$stmt->execute();

$stmt->bind_result($lid, $hostName, $str);
while($stmt->fetch()){

    $users=0;
    $on = 1;
    //echo $lid;
    $stmt2= $mysqli->prepare('SELECT  `user_id`  FROM `tbl_usersInLobbies` WHERE lobby_id = ?');
    $stmt2->bind_param('i', $lid);
    echo 1;
    $stmt2->execute();
    $stmt2->bind_result($users);
    while($stmt2->fetch()){
        echo 1;
     $nou .= '&nbsp<i class="fa fa-square" aria-hidden="true"></i>';
    }
    $stmt2->close();

This code only works if I open another connection in the loop. I know that isnt effective so im trying to see if there is another way. I know there is no variable errors in the code. I would use another form of sql in there is no other option. PS im still a student so im sorry for any obvious answers.

Use just 1 SQL query, something like this:

SELECT tbl_lobbies.lobby_id, tbl_lobbies.user_penName, tbl_lobbies.lobby_str, tbl_usersInLobbies.user_id 
FROM `tbl_lobbies` 
JOIN tbl_users ON tbl_lobbies.user_id = tbl_users.user_id 
LEFT JOIN `tbl_usersInLobbies` ON tbl_usersInLobbies.lobby_id = tbl_lobbies.lobby_id
WHERE lobby_active = ?