Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7802385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:14:54+00:00 2026-06-02T01:14:54+00:00

I recently created a scoring system where the users are ordered by their points

  • 0

I recently created a scoring system where the users are ordered by their points on descending basis. First I used to store ranks in a column of its own. I used to run this loop to update the rank:

$i = 1;
    $numberOfRows = mysql_query('SELECT COUNT(`id`) FROM sector0_players');
    $scoreboardquery = mysql_query("SELECT * FROM sector0_players ORDER BY points DESC");
    while(($row = mysql_fetch_assoc($scoreboardquery)) || $i<=$numberOfRows){
        $scoreid = $row['id'];
        $mysql_qeury = mysql_query("UPDATE sector0_players SET scoreboard_rank = '$i' WHERE id = '$scoreid'");
    $i++;
    }

And it was really hard, not to mention slow to actually run this on a huge amount of users.
Instead, I tried to construct a query and ended up with this.

SET @rownum := 0;
SELECT scoreboard_rank, id, points
FROM (
SELECT @rownum := @rownum + 1 AS scoreboard_rank, id, points FROM sector0_players ORDER BY points DESC
)
as result WHERE id = '1';

But, this is just a select statement. Is there anyway I could get around it and change it so that it updates the table just as the loop does?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:14:56+00:00Added an answer on June 2, 2026 at 1:14 am

    Please try using the following query :

    set @rownum:=0;
    update sector0_players set scoreboard_rank=@rownum:=@rownum+1 ORDER BY points DESC;
    

    PHP code can be ,

    mysql_query("set @rownum:=0;");
    mysql_query("update sector0_players set scoreboard_rank=@rownum:=@rownum+1 ORDER BY points DESC;");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently created my first bash script, and I am having problems perfecting it's
I recently created my first android live wallpaper and it would not work on
I have recently created an Android application that allows users to add shopping items
i have recently created my first app and got it onto my ipad, however,
I recently created my first custom control. I attempted to add it in a
I recently created my first custom control. I attempted to add it in a
I've recently created a dropbox system using inotify, watching for files created in a
I recently created my first Heroku application and I'm finding some strange behavior: When
I recently created a PHP/MySQL comment system, and it was working until a few
I recently created a (C#) project with Visual Studio (2010) and used some Settings

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.