这就是我现在正在使用的。我成功获取第一个查询,但是我无法从第二个查询中检索任何数据。第二个查询的所有变量都是未定义的。
$sql = "SELECT * FROM history WHERE ended=1 ORDER BY chance ASC LIMIT 1";
$result = $conn->query($sql);
$row = mysqli_fetch_assoc($result);
$luck_steamid = $row["winner"];
$luck_total = $row["total"];
$luck_chance = $row["chance"];
$luck_round = $row["id"];
$sql = "SELECT * FROM users WHERE steamid=".$luck_steamid;
$result = $conn->query($sql);
$row = mysqli_fetch_assoc($result);
$luck_avatar = $row["avatar"];
$luck_name = $row["name"];
$luck_profile = $row["profile"];
答案 0 :(得分:0)
使用连接即可一次性获取所有内容:
$sql = "SELECT history.winner, history.total, history.chance, history.id, users.avatar, users.name, users.profile FROM history JOIN users ON history.winner = users.steamid WHERE ended=1 ORDER BY chance ASC LIMIT 1";
$result = $conn->query($sql);
$row = mysqli_fetch_assoc($result);
$luck_steamid = $row["winner"];
$luck_total = $row["total"];
$luck_chance = $row["chance"];
$luck_round = $row["id"];
$luck_avatar = $row["avatar"];
$luck_name = $row["name"];
$luck_profile = $row["profile"];