Jump to content

Recommended Posts

Posted

Gentlemen, hi again:

i wrote this code to show total passengers carried by pilot

<?php

$query = "SELECT SUM(load) as totalpax FROM phpvms_1pireps WHERE pilotid = '$pilotid' ";

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

echo $result[0]->totalpax; ?></td>

Dont work,

Any help is welcome.

Best regards.

Posted

You don't need the [0].

<?php
$query = "SELECT SUM(load) as totalpax FROM phpvms_1pireps WHERE pilotid = '$pilotid' ";
$result=DB::get_results($query);
echo $resul->totalpax;
?>

I assume this is a module function?

  • Administrators
Posted

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

Posted

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

Posted

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);?>

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