RuiMiguel Posted January 27, 2018 Report Share Posted January 27, 2018 Hello I need help for this code: <?php function getTotalScore() { $query = "SELECT SUM(`final_score`) AS final_score FROM ".TABLE_PREFIX."pireps WHERE pilotid = ".$pilotid." AND accepted = 1"; $result = DB::get_row($query); if (!$result) return 0; return ($result->score == '') ? 0 : $result->score; } ?> <?php echo getTotalScore(); ?> the result is 0 Can someone help me? Thanks Rui Miguel Quote Link to comment Share on other sites More sharing options...
Moderators servetas Posted January 27, 2018 Moderators Report Share Posted January 27, 2018 Your function has a few errors. First of all. you are saying "SUM(`final_score`) AS final_score" which means that the return will be titled as final_score and then you are doing an if using the title score. In " return ($result->score == '') ? 0 : $result->score; " you will have to replace score with final_score. Also, where are you getting the $pilotid variable in the function from? You should pass it in the function arguments or remove it. Have you added the final_score column in the pireps table? Quote Link to comment Share on other sites More sharing options...
RuiMiguel Posted January 27, 2018 Author Report Share Posted January 27, 2018 (edited) yes I have a final score in the database on pireps this code is on the pilots_list Can you explain to me how I get the variable for $pilotid thanks Edited January 27, 2018 by RuiMiguel Quote Link to comment Share on other sites More sharing options...
Moderators servetas Posted January 27, 2018 Moderators Report Share Posted January 27, 2018 This is an English speaking forum plus the fact that I do not speak French yet :D. Please write in English Quote Link to comment Share on other sites More sharing options...
RuiMiguel Posted January 27, 2018 Author Report Share Posted January 27, 2018 i have this in profile main it works function getTotalScore() { $query = "SELECT SUM(`final_score`) AS score FROM ".TABLE_PREFIX."pireps WHERE pilotid = ".Auth::$userinfo->pilotid." AND accepted = 1"; $result = DB::get_row($query); if (!$result) return 0; return ($result->score == '') ? 0 : $result->score; } 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.