Skip navigation
Currently Being Moderated

Updating scores table and updating rank with php.

Feb 14, 2012 11:24 AM

Tags: #php

Hi

 

 

I have a scores table on my site that is 

 

Scores : id - userid - rank - points -

 

While using the site  users get points for doing stuff. The points are updated, but I don`t know how

to update the rank of that user by comparing every one elses points and updating the rank numbers

based on the users with most points in php.

 

Hope you can help. Thanks

 
Replies
  • Currently Being Moderated
    Feb 16, 2012 9:39 PM   in reply to Tony404

    Pull all the users from database sorted by points /// SELECT * FROM scores ORDER BY points DESC

    Create a loop within database records. /// Using while or foreach

    Create a counter outside the loop /// $count = 0

    Increase the count ($count++) inside the loop /// this will be your new ranking

    Update scores table with new ranking /// UPDATE scores SET rank = '{$count}' WHERE id = '{$db_resultsl["id"]}'

     

    Hope this helps...

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points