Jump to content

Recommended Posts

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
 

 

 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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 by RuiMiguel

Share this post


Link to post
Share on other sites

This is an English speaking forum plus the fact that I do not speak French yet :D. Please write in English

Share this post


Link to post
Share on other sites

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;
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×