Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mysql已准备好获取循环,不会对循环stmt使用连接_Php_Mysql_Sql - Fatal编程技术网

Php mysql已准备好获取循环,不会对循环stmt使用连接

Php mysql已准备好获取循环,不会对循环stmt使用连接,php,mysql,sql,Php,Mysql,Sql,感谢所有愿意帮忙的人。我试图在另一个SELECT循环的fetch循环中运行sql SELECT $mysqli = connect(); $stmt= $mysqli->prepare('SELECT lobby_id, user_penName, lobby_str FROM `tbl_lobbies` JOIN tbl_users ON tbl_lobbies.user_id =

感谢所有愿意帮忙的人。我试图在另一个SELECT循环的fetch循环中运行sql SELECT

$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();
$mysqli=connect();
$stmt=$mysqli->prepare('SELECT lobble\u id,user\u penName,lobble\u str
来自“tbl_大厅”
在tbl_大厅加入tbl_用户。用户id=tbl_用户。用户id
其中,大堂_活动=?');
$stmt->bind_参数('i',$on);
$stmt->execute();
$stmt->bind_result($lid、$hostName、$str);
而($stmt->fetch()){
$users=0;
$on=1;
//回声$lid;
$stmt2=$mysqli->prepare('tbl_usersInLobbies`WHERE lobby_id=?'中选择'user_id');
$stmt2->bind_参数('i',$lid);
回声1;
$stmt2->execute();
$stmt2->bind_result($users);
而($stmt2->fetch()){
回声1;
$nou.='nbsp';
}
$stmt2->close();
只有在循环中打开另一个连接时,此代码才有效。我知道这无效,所以我正在尝试查看是否有其他方法。我知道代码中没有变量错误。我将使用其他形式的sql,因为没有其他选项。
PS我仍然是一名学生,所以对于任何显而易见的答案,我感到抱歉。

仅使用一个SQL查询,如下所示:

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 = ?

我会的,但是当我只需要一次时,我需要多次tbl_大厅记录。我需要用户id,他们在大厅中的位置。这是我没有正确解释的错误是的,因为您正在使用
fetch()
将其更改为
fetch(PDO::fetch_ASSOC)
和woala.:)如果有效,请提交+1这将比在循环中进行查询更高效