freshJet Posted July 1, 2013 Report 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
Members Vangelis Posted July 1, 2013 Members Report Posted July 1, 2013 What kind of id do you pass ? For ex avs001 or 001? Quote
Moderators Parkho Posted July 2, 2013 Moderators Report 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
Tom Posted July 2, 2013 Report 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
freshJet Posted July 2, 2013 Author Report 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
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.