Jump to content

Recommended Posts

Posted

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

  • Moderators
Posted

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'";

Posted

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

Posted

I'll give it a go. It was confusing me because it worked for other fields, for example I tested it using flightnum and it added all of the flight numbers fine.

EDIT: Thanks a lot, that's sorted it ;)

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