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循環內循環數據庫中的數據。 –
你怎麼知道這個*查詢*只返回一行? –