我在我的json響應中獲得了第1行,第2行和第3行的相同值。第2行顯示的假設結果顯示在第2列,第1列假設的第3個結果顯示在第3列。我試過一切,並改變查詢仍然沒有好處。在此先感謝我的sql查詢返回json響應中3行的相同數據類型
$sql = "select
e_name,
a_shortcut,
case
when t_rank = 1 then '1st'
when t_rank = 2 then '2nd'
when t_rank = 3 then '3rd'
end as t_rank
from
team inner join event on team.EID = event.eid Where e_type = 'nonsport' group by event.eid";
$con = mysqli_connect($server_name,$mysql_user,$mysql_pass,$db_name);
$result = mysqli_query($con,$sql);
$response = array();
while($row=mysqli_fetch_array($result))
{
array_push($response, array("e_name"=>$row[0],"1st"=>$row[1],
"2nd"=>$row[2], "3rd"=>$row[2]));
}
echo json_encode (array("nresults"=>$response));
這裏是什麼即時獲取我的服務器響應,如果我的第二和第三行是[2]和[2]。
{"nresults":[{"e_name":"Amateur Photography Contest","1st":"AAA","2nd":"3rd","3rd":"3rd"}]}
如果我改變
1st"=>$row[1],
"2nd"=>$row[2], "3rd"=>$row[2] into 1st"=>$row[1],
"2nd"=>$row[1], "3rd"=>$row[1]
它變成這樣
{"nresults":[{"e_name":"Amateur Photography Contest","1st":"AAA","2nd":"AAA","3rd":"AAA"}]}
我的預期輸出。其中AAA爲1級,BBB是2,CCC爲3
這樣
{"nresults":[{"e_name":"Amateur Photography Contest","1st":"AAA","2nd":"BBB","3rd":"CCC"}]}
哪列是 '1' 的查詢? –
擺脫所有非MySQL的東西,看到http://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-一個非常簡單的SQL查詢 – Strawberry
@DaniloBustos第1第2和第3應該是a_shortcut,根據他們的排名 – orange