gpt4 book ai didi

php - SQL查询只返回一行结果

转载 作者:行者123 更新时间:2023-11-29 19:49:10 25 4
gpt4 key购买 nike

我的查询结果只得到一行。我需要得到三个结果,但它只显示一行结果。我尝试尽可能多地更改代码,但结果中显示的内容不超过一行。我的代码如下。

elseif($module=="winners")
{

$result = mysqli_query($conn,"SELECT * FROM `contest` WHERE showresult=1");
if (mysqli_num_rows($result) > 0) {

$result = mysqli_query($conn,"select * FROM `contest_score` order by score desc, CAST(timequiz as DECIMAL(9,2)) ASC limit 0,3");
if (mysqli_num_rows($result) > 0) {

$response["scores"] = array();

while ($row = $result->fetch_assoc()) {
$scores = array();
$scores["id"] = $row["id"];
$scores["user_id"] = $row["user_id"];
$scores["username"] = $row["username"];
$scores["score"] = $row["score"];
$scores["played_date"] = $row["played_date"];
$scores["timequiz"] = $row["timequiz"];
$user_id = $row["user_id"];
$result = mysqli_query($conn,"SELECT user_image FROM `users` WHERE id=$user_id");
$temp_row = mysqli_fetch_assoc($result);

$scores["user_image"] = $temp_row["user_image"];

array_push($response["scores"], $scores);
}
$response["success"] = 1;

// echoing JSON response
echo json_encode($response);

请检查并告诉我是否有人可以帮助我解决我的问题。

谢谢

最佳答案

这可能与此有关:您正在循环中重写您的 $result 变量。

$result = mysqli_query($conn,"从 'users' WHERE id=$user_id 中选择 user_image");

关于php - SQL查询只返回一行结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40866919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com