0
我得到的查询结果只有一行。我需要得到三个结果,但结果只显示一行。我试图尽可能地更改代码,但结果中没有显示多行。我的代码如下所示。SQL查询返回结果中只有一行
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);
请检查并让我知道如果有人能帮助我解决了我的问题。
感谢
我想你应该在WHILE循环内循环数据库中的数据。 –
你怎么知道这个*查询*只返回一行? –