Jump to content

Get how many passengers a pilot has carried [SOLVED]


freshJet

Recommended Posts

Going back to this after a few months, still no avail:


public function totalPax($pilotid){
$query = "SELECT SUM(load) AS totalpax FROM phpvms_pireps WHERE pilotid = '".$pilotid."'";
$result = DB::get_row($query);
return $result->totalpax;
}

I am completely stumped. The only thing that comes to mind is that the field name is wrong, but I checked and right enough it is called 'load'.

Link to comment
Share on other sites

  • Moderators

This is wrong:

$query = "SELECT SUM(load) AS totalpax FROM phpvms_pireps WHERE pilotid = '".$pilotid."'";

Try this:

$query = "SELECT SUM(load) AS totalpax FROM phpvms_pireps WHERE pilotid = '$pilotid'";

Link to comment
Share on other sites

This is wrong:

$query = "SELECT SUM(load) AS totalpax FROM phpvms_pireps WHERE pilotid = '".$pilotid."'";

Try this:

$query = "SELECT SUM(load) AS totalpax FROM phpvms_pireps WHERE pilotid = '$pilotid'";

His original use of quotes was better.

Here's a working query, which will also return 0 instead of NULL if there are no rows:

 $query = "SELECT COALESCE(SUM(`load`),0) AS totalpax FROM ".TABLE_PREFIX."pireps WHERE pilotid =  '".$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...