I'm using this:
<?php
$dbm="SELECT t1.pilotid,t1.distance,t2.firstname,t2.lastname FROM
(SELECT
pilotid, sum(distance) as distance
FROM phpvms_pireps
WHERE date_format(submitdate, '%Y-%m') = date_format(now(), '%Y-%m') AND accepted = 1
GROUP BY pilotid) t1
LEFT JOIN phpvms_pilots t2 ON t1.pilotid = t2.pilotid
ORDER BY distance DESC LIMIT 10";
$bstm = DB::get_results($dbm);
foreach ($bstm as $btm)
{
if($bstm == '')
{
?>
<tr><td align="center" colspan="2">No Records yet!</td></tr>
<?php
}
else
{
?>
<tr><td><?php echo $btm->lastname ;?></td><td align="center"><?php echo $btm->distance ;?> NM</td></tr>
<?php
}
}
?>
This will give u top miles in current month.
If you need top miles for all time use this:
<?php
$dbm="SELECT t1.pilotid,t1.distance,t2.firstname,t2.lastname FROM
(SELECT
pilotid, sum(distance) as distance
FROM phpvms_pireps
WHERE accepted = 1
GROUP BY pilotid) t1
LEFT JOIN phpvms_pilots t2 ON t1.pilotid = t2.pilotid
ORDER BY distance DESC LIMIT 10";
$bstm = DB::get_results($dbm);
foreach ($bstm as $btm)
{
?>
<tr><td><?php echo $btm->lastname ;?></td><td align="center"><?php echo $btm->distance ;?> NM</td></tr>
<?php
}
?>