gpt4 book ai didi

php - foreach 循环内数据未按升序显示

转载 作者:行者123 更新时间:2023-11-29 22:08:11 25 4
gpt4 key购买 nike

我有一个存储在 $finalvendorid 中的数组,如下所示

Array
(
[0] => Array
(
[id] => 14
[vendorid] => 26
[area] => N1
)

[1] => Array
(
[id] => 13
[vendorid] => 33
[area] => N1
)

[2] => Array
(
[id] => 15
[vendorid] => 37
[area] => N1
)

)

从中我需要获取供应商ID并显示其数据。我尝试使用 foreach 循环然后显示数据,我正确地获取了数据,但无法按升序显示它(acc to avgating)

供应商表的演示 View 是

id  vendorname  vendordesc  avgrating
26 V1 VD1 2
33 V2 VD2 3
37 V3 VD3 1

循环代码

<?php
foreach ($finalvendorid as $keyy => $valuee)
{
$newvendorid = $valuee['vendorid'];
$sql01 = "SELECT * FROM vendor where id='".$newvendorid."' ORDER BY avgrating ASC";
//echo $sql01;
$result01 = mysqli_query($con, $sql01);
if (mysqli_num_rows($result01) > 0)
{
while($row01 = mysqli_fetch_assoc($result01))
{
//displaying of data
}
}
}
?>

谁能告诉我如何按升序排列数据,以便我按以下顺序获得供应商的 O/P

first vendor with id 37 should get displayed, 
then vendor with id 26 should get displayed and
finally vendor with id 33 should get displayed

最佳答案

替换

ORDER BY avgrating DESC

ORDER BY avgrating

关于php - foreach 循环内数据未按升序显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31956952/

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