freshJet Posted July 1, 2013 Report Share Posted July 1, 2013 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'. Quote Link to comment Share on other sites More sharing options...
Members Vangelis Posted July 1, 2013 Members Report Share Posted July 1, 2013 What kind of id do you pass ? For ex avs001 or 001? Quote Link to comment Share on other sites More sharing options...
Moderators Parkho Posted July 2, 2013 Moderators Report Share Posted July 2, 2013 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'"; Quote Link to comment Share on other sites More sharing options...
Tom Posted July 2, 2013 Report Share Posted July 2, 2013 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."'"; Quote Link to comment Share on other sites More sharing options...
freshJet Posted July 2, 2013 Author Report Share Posted July 2, 2013 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.