$row[1], "2nd"=>$row[2], "3rd"=>$row[3]-6ren">
gpt4 book ai didi

php - 我的选择查询返回 3 行的相同数据

转载 作者:行者123 更新时间:2023-11-28 23:19:56 25 4
gpt4 key购买 nike

我得到的第 1、第 2 和第 3 个值相同。然后下一行给出了应该在第一行的第二列中的结果。

<?php  
require "db.php";
$sql = "
SELECT e_name
, IF(t_rank = 1, a_shortcut, a_shortcut) AS 1st
, IF(t_rank = 1, a_shortcut, a_shortcut) AS 2nd
, IF(t_rank = 3, a_shortcut, a_shortcut) AS 3rd
FROM team t
JOIN event e
ON t.EID = e.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[3]));

}
echo json_encode (array("nresults"=>$response));



mysqli_close($con);

?>

我的预期输出是

例子。 快捷方式有 a、b、c,它们的等级为 a =1 b =2 c =3;

然后 1st = a, 2nd = b, 3rd = c;

我得到的是

1st = a, 2nd = a, 3rd = a;

然后下一行显示

1st = b, 2nd = b, 3rd = b;

最佳答案

$sql = "select e_name
, IF(t_rank = 1,'A',NULL) AS 1st
, IF(t_rank = 2,'B',NULL) AS 2nd
, IF(t_rank = 3,'C',NULL) as 3rd
from team t
join event e on t.EID = e.EID";

这将返回 A、B、C 格式的排名。当条件匹配时,它将转换为 A、B、C 格式

关于php - 我的选择查询返回 3 行的相同数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42173995/

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