gpt4 book ai didi

php - 选择插槽最大的行

转载 作者:行者123 更新时间:2023-11-30 23:39:22 24 4
gpt4 key购买 nike

我需要选择 slot_left 最大的一行。我试过了

for ( $i=1;$i<3;$i++) {
$sql5 = "SELECT * from user u where (
select max(slot_left) from company c,user u
where c.id=u.company_id and c.id='$name'
)";
$result5 = mysqli_query($link, $sql5) or die(mysqli_error($link));
while($row=mysqli_fetch_array($result5)) {
// echo the id which the slot_left is the biggest
echo $i['slot_left'];
}
}

但还是不行。请帮忙!

最佳答案

您必须在查询中使用 GROUP BY。并且不推荐在 Loop 中执行查询,它会降低性能。

试试这个。

$sql5 = "select c.id, max(slot_left) from company c,user u 
where c.id=u.company_id and c.id='$id' GROUP by c.id";

$result5 = mysqli_query($link, $sql5) or die(mysqli_error($link));
while($row=mysqli_fetch_array($result5)) {
echo $row['slot_left'];
}

关于php - 选择插槽最大的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4733084/

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