Skip to main content
February 14, 2012
Question

Updating scores table and updating rank with php.

  • February 14, 2012
  • 1 reply
  • 592 views

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

This topic is closed to new replies. Start a new post to keep the conversation going.

1 reply

February 17, 2012

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...