Jump to content

Pax per Pilot


chilemugriento

Recommended Posts

  • Administrators

"load" is a reserved word in MySql so it needs to be escaped in order to be used in anything outside of its function. Also "get_results($sql)" is going to return an array when in this case you want an object so you should use "get_row()"

$query = "SELECT SUM(`load`) AS `total_pax` FROM ".TABLE_PREFIX."pireps WHERE pilotid = $pilotid";
$result = DB::get_row($query);

echo $result->total_pax;

This works as long as you have the correct variable for the $pilotid. I would also suggest putting the sql query into a model and not in your template.

Link to comment
Share on other sites

SOLVED !!!!

Here is:

function getTotalPassengersPilot()

{

$query = "SELECT SUM(`load`) AS passengers FROM ".TABLE_PREFIX."pireps WHERE pilotid = ".Auth::$userinfo->pilotid." AND accepted = 1";

$result = DB::get_row($query);

if (!$result) return 0;

return ($result->passengers == '') ? 0 : $result->passengers;

}

and

<?php echo number_format (getTotalPassengersPilot());?>

Best regards

Link to comment
Share on other sites

I have added this to StatsData.class and had to make a small change but not major:

In StatsData.class.php:

   public function getTotalPassengersPilot($pilotid)
   {
       $query = "SELECT SUM(`load`) AS passengers FROM ".TABLE_PREFIX."pireps WHERE pilotid = $pilotid AND accepted = 1";
       $result = DB::get_row($query);
       if (!$result) return 0;
       return ($result->passengers == '') ? 0 : $result->passengers;
   }

In your pilots_list or pilot_public_profile.tpl:

<?php echo StatsData::getTotalPassengersPilot($userinfo->pilotid);?>

Link to comment
Share on other sites

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...