chilemugriento Posted July 16, 2014 Report Share 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 Link to comment Share on other sites More sharing options...
alblua Posted July 21, 2014 Report Share 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 Link to comment Share on other sites More sharing options...
freshJet Posted July 21, 2014 Report Share 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 Link to comment Share on other sites More sharing options...
chilemugriento Posted July 21, 2014 Author Report Share Posted July 21, 2014 Its a code inserted into pilot_list tpl Quote Link to comment Share on other sites More sharing options...
Strider Posted July 21, 2014 Report Share Posted July 21, 2014 Well first the $pilotid should be: $pilot->pilotid Quote Link to comment Share on other sites More sharing options...
OA01 Posted July 26, 2014 Report Share Posted July 26, 2014 Doesnt matter which way you write this code, it doesn't work??? Quote Link to comment Share on other sites More sharing options...
freshJet Posted July 26, 2014 Report Share Posted July 26, 2014 Your table is probably phpvms_pireps Quote Link to comment Share on other sites More sharing options...
Strider Posted July 27, 2014 Report Share 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 Link to comment Share on other sites More sharing options...
freshJet Posted July 27, 2014 Report Share Posted July 27, 2014 What code did you use? Quote Link to comment Share on other sites More sharing options...
Administrators simpilot Posted July 27, 2014 Administrators Report Share 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 Link to comment Share on other sites More sharing options...
chilemugriento Posted July 28, 2014 Author Report Share 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 Link to comment Share on other sites More sharing options...
Strider Posted July 28, 2014 Report Share 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 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.