在我的数据库中,我有一个名为db_pilots
的表格,我正试图找到来自国家的总数,即来自GB
的飞行员总数。它正是这样做的,但它按location
而不是total
排序。我怎样才能做到这一点?
<?php
$country_info = DB::get_results('SELECT COUNT(pilotid) as total, location FROM'.TABLE_PREFIX.'pilots GROUP BY location DESC');
foreach($country_info as $country)
{
?>
<tr>
<td align="center"><img src="<?php echo Countries::getCountryImage($country->location); ?>" /></td>
<td align="center"><?php echo Countries::getCountryName($country->location); ?></td>
<td align="center"><?php echo $country->total;?></td>
</tr>
<?php
}
?>
答案 0 :(得分:1)
尝试添加ORDER BY:
...GROUP BY location ORDER BY total DESC
答案 1 :(得分:0)
FROM
之后你错过了一个空格:
FROM'.TABLE_PREFIX.'pilots
^
应该是这样的:
FROM '.TABLE_PREFIX.'pilots