gpt4 book ai didi

php - 按添加的变量对数组进行排序

转载 作者:行者123 更新时间:2023-11-30 00:43:47 24 4
gpt4 key购买 nike

将变量添加到 mysql 查询的末尾。现在我需要能够按关联值进行排序。有人可以帮忙吗?我尝试了几种不同的排序方法。

$result2 = mysqli_query($datacon,
"SELECT * FROM spreadsheet
WHERE brand = '$brand'
AND package = '$package'
AND HIDE_FROM_SEARCH = '0'
GROUP BY ACCTNAME $pages->limit");

echo mysqli_error($datacon);
while($row = mysqli_fetch_array($result2)) {
$lat_B=$row['LATITUDE'];
$long_B=$row['LONGITUDE'];

$lat_A = round($lat_A,2);
$long_A = round($long_A,2);
$lat_B = round($lat_B,2);
$long_B = round($long_B,2);
$distance = new calcDist($lat_A, $long_A, $lat_B, $long_B);
$distance = $distance->calcDist($lat_A, $long_A, $lat_B, $long_B);
$distance = round($distance,2);
$locationSort=array($row);
$locationSort['distance']=$distance;

FOR EACH SOMETHING?
}

我修改了之前的帖子以反射(reflect)我对答案的使用。

$result2 = mysqli_query($datacon,"SELECT * FROM spreadsheet WHERE brand = '$brand'
AND package = '$package' and HIDE_FROM_SEARCH = '0' GROUP BY ACCTNAME $pages->limit");

echo(mysqli_error($datacon));
class sortBydistance
{
function sortBydistance($a, $b) {
if ($a['distance'] == $b['distance']) {
return 0;
}
return ($a['distance'] < $b['distance']) ? -1 : 1;
}
}
while($row = mysqli_fetch_array($result2))
{
$lat_B=$row['LATITUDE'];
$long_B=$row['LONGITUDE'];

$lat_A = round($lat_A,2);
$long_A = round($long_A,2);
$lat_B = round($lat_B,2);
$long_B = round($long_B,2);
$distance = new calcDist($lat_A, $long_A, $lat_B, $long_B);
$distance = $distance->calcDist($lat_A, $long_A, $lat_B, $long_B);
$distance = round($distance,2);


}
$locationSort=array($row);
$locationSort['distance']=$distance;
uasort($locationSort, array($this, "sortBydistance"));
print_r($locationSort);

最佳答案

可能您没有正确检索 $bran 和 $package 变量..

$result2 = mysqli_query($datacon,
"SELECT * FROM spreadsheet
WHERE brand = '".$brand."'
AND package = '".$package."'
AND HIDE_FROM_SEARCH = '0'
GROUP BY ACCTNAME ".$pages->limit.");

关于php - 按添加的变量对数组进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21558602/

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