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
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?
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
This is an English speaking forum plus the fact that I do not speak French yet :D. Please write in English
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;
}