chilemugriento Posted July 16, 2014 Report Posted July 16, 2014 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. Quote
alblua Posted July 21, 2014 Report Posted July 21, 2014 Did you connect to the database yet? Doesn't seem like it in here. Or is it within a file that already connects to it? Quote
freshJet Posted July 21, 2014 Report Posted July 21, 2014 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? Quote
chilemugriento Posted July 21, 2014 Author Report Posted July 21, 2014 Its a code inserted into pilot_list tpl Quote
Strider Posted July 21, 2014 Report Posted July 21, 2014 Well first the $pilotid should be: $pilot->pilotid Quote
OA01 Posted July 26, 2014 Report Posted July 26, 2014 Doesnt matter which way you write this code, it doesn't work??? Quote
Strider Posted July 27, 2014 Report Posted July 27, 2014 I have tried the code, and it does not work. It needs some tweaking to find a piece of code that does. Quote
Administrators simpilot Posted July 27, 2014 Administrators Report Posted July 27, 2014 "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. Quote
chilemugriento Posted July 28, 2014 Author Report Posted July 28, 2014 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 Quote
Strider Posted July 28, 2014 Report Posted July 28, 2014 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);?> 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.