Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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...
Find more inspiration, events, and resources on the new Adobe Community
Explore Now