使用php按字母顺序排序数据

时间:2013-08-31 01:47:41

标签: php

我从数据库中获取数据,我想按字母顺序对hotel_name进行排序。我怎么能用php的sort函数或任何其他方法来做呢?

foreach($selData as $row)
{
    $name=$row['hotel_name']; 
    $distance_colombo=$row['distance_colombo'];
    $distance_airport=$row['distance_airport'];
    $description=$row['description'];
    $activities=$row['activities'];
    $str=(explode(',',$activities));
    print_r($str);
}

1 个答案:

答案 0 :(得分:2)

此处无需使用sort()。只需在SQL查询中使用ORDER BY

示例:

SELECT * FROM table_name ORDER BY hotel_name