Jump to content

Recommended Posts

Posted

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
 

 

 

  • Moderators
Posted

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?

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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...