douren1891 2011-09-06 15:38
浏览 91

PHP对循环的结果进行排序并在屏幕上显示

I was wondering if someone could point me in the right direction with a coding issue Im having.

I am running a while loop in PHP comparing a post code to another and each run of the loop generates distance data. What Id like to do is then sort this data and display it.

Usually I'd throw everything into a MySQL database then sort that way but I think thats over kill.

Here's an example of the loop :

while($row = mysql_fetch_array($result))
{

    $info = get_driving_information($_POST['customerpostcode'], $row[instructor_postcode]); 

echo $row['instructor_name']  . " - " . $info['distance'];  
}

I know this is probably PHP 101 but Ive never had to do anything like this before and am not sure how.

Thanks in advance for reading,

Rik

  • 写回答

4条回答 默认 最新

  • dsgo31121 2011-09-06 15:44
    关注

    I think this is what you mean:

    $rows = array();
    while($row = mysql_fetch_array($result))
    {
        $info = get_driving_information($_POST['customerpostcode'], $row[instructor_postcode]); 
        $row['distance'] = $info['distance']; // store it in the array
    
        $rows[] = $row;
    }
    

    Then use usort to sort the $rows array by the distance key.

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算