我正在为 Drupal 7 项目处理此查询:
$group = taxonomy_get_tree(2);
$group_list = "";
$total_countries_list = "";
foreach ($group as $member) {
$countries_list = "";
$id = str_replace(' ', '-', $member->name);
$id = str_replace('/', '-', $id);
$group_list .= '<li><a id="link-' . str_replace(' ', '-', $id) . '" href="#">. ' . $member->name . '</a></li>';
$results = db_query('SELECT n.title AS name, fdfea.field_email_address_value AS email
FROM node AS n
LEFT JOIN field_data_field_email_address AS fdfea ON fdfea.entity_id = n.nid
LEFT JOIN field_data_field_group_of_countries AS fdfgoc ON fdfgoc.field_group_of_countries_tid = :country_taxonomy
WHERE n.nid = fdfgoc.entity_id', array(':country_taxonomy' => $member->tid));
$i = 0;
foreach ($results as $country) {
if ($i % 13 == 0){
$countries_list .= '</ul><ul>';
}
$countries_list .= '<li><a href="mailto:' . $country->email . '">' . $country->name . '</a></li>';
$i++;
}
$countries_list = '<ul>' . $countries_list . '</ul>';
$total_countries_list .= '<div class="countries-list" id="' . $id . '">' . $countries_list . '</div>';
}
$total_countries_list = '<div class="countries-wrapper">' . $total_countries_list . '</div>';
$group_list = '<ul class="big-list">' . $group_list . '</ul>';
return $group_list . $total_countries_list;
我正在使用此查询的结果来形成国家/地区列表。查询工作正常,但我还需要按字母顺序对每个组中的国家/地区进行排序。ORDER BY 显然不是这样做的方法,所以我该如何进行排序?