Jump to content

How to know how many miles flown by the pilot


Kairon

Recommended Posts

  • 10 months later...
Guest lorathon

In whatever query for the pireps you are using you need to add the following

SUM(distance) as totalmiles

Example - (NOT TESTED!)


public static function getPilotInfoWithTotalDistance($pilotid) {

$sql = 'SELECT p.*, u.*,
       SUM(p.distance) as totalmiles
       FROM '.TABLE_PREFIX.'pireps p
       LEFT JOIN '.TABLE_PREFIX.'pilots u ON u.pilotid = p.pilotid
       WHERE p.pilotid = '.$pilotid
       ;

$ret = DB::get_row($sql);

return $ret;
}

Link to comment
Share on other sites

I'm trying to place the code to have it show in the profile_main.tpl with the rest of the pilot information about the member. I am trying to figure out which call to use for it.

This isn't working:

<li><strong>Miles Flown: </strong><?php echo $userinfo->totalmiles; ?></li>

I'm sure the code you just gave, goes in the PilotData.php, but trying to figure the pull code.

Link to comment
Share on other sites

Guest lorathon

Actaully the code I gave should be places in a data file.

Lets call it CUSTOMData.class.php. This file would go into the core/common folder. The file would have the contents of.....

<?php
class CUSTOMData extends CodonData
{	
   public static function getPilotInfoWithTotalDistance($pilotid) {

   $sql = 'SELECT p.*, u.*,
           SUM(p.distance) as totalmiles
           FROM '.TABLE_PREFIX.'pireps p
           LEFT JOIN '.TABLE_PREFIX.'pilots u ON u.pilotid = p.pilotid
           WHERE p.pilotid = '.$pilotid
           ;

   $ret = DB::get_row($sql);

   return $ret;
   }
}

From the profile_main.tpl you would call as such......

<?php
$custom_info = CUSTOMData::getPilotInfoWithTotalDistance($userinfo->pilotid);
echo 'Total Flown Miles: '.$custom_info->totalmiles;
?>

Now I havent actually tested the function but it should work.

Link to comment
Share on other sites

Actually you did a great job on it. It works perfectly now. Thanks a lot on the help.

Other interested parties wondering how to do it, follow Jeffrey's examples then in the profile_main.tpl place this in the lineup:

<li><?php
$custom_info = CUSTOMData::getPilotInfoWithTotalDistance($userinfo->pilotid);
echo '<strong>Total Flown Miles: </strong>'.$custom_info->totalmiles;
?></li>

The same exact code above will also work in the pilot_public_profile.tpl without any modifications.

Link to comment
Share on other sites

  • 4 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...