Jump to content

A rank users order by points


alexcsandru

Recommended Posts

I want to make an insert from table 'rank' , with number (rank) from the cod blow, to fild users.rank ...

 

set @rank := 0;

select @rank:=@rank+1 'rank', users.username, users.points from users order by points desc;

+------+-------------+--------+
| rank | username    | points |
+------+-------------+--------+
|    1 | ropy        |     98 |
|    2 | alexcsandru |     17 |
|    3 | bobo        |     17 |
|    4 | ovidiu      |      5 |
+------+-------------+--------+

 

How to do??

 

P.S.: to insert rank in users.rank table... and with a function  reload_player_rank() of 30 in 30 minutes (to update new rank in table users.rank) .

 

 

A solution please,

Thank you!

Link to comment
Share on other sites

To be more exactly ..

I have table users ... something link that

+----+-------------+----------+--------+--------------+--------+------+
| id | username    | password | banned | colonization | points | rank |
+----+-------------+----------+--------+--------------+--------+------+
|  1 | alexcsandru | ******   | N      |            1 |     17 |    0 |
|  2 | ovidiu      | ******   | N      |            1 |      5 |    0 |
|  3 | ropy        | ******   | N      |            1 |     98 |    0 |
|  4 | bobo        | ******   | N      |            1 |     17 |    0 |
+----+-------------+----------+--------+--------------+--------+------+

 

and i want to update rank table, where is 0 with rank users ordered by points...

 

I need to display that with $smarty template (users.username, users.points, users.rank) , and more function of the game!

 

I build a game browser based !

 

Have a solution ?

 

Sorry for my english! :D

Link to comment
Share on other sites

Hi

 

Think I found a solution for you.

 

CREATE temporary table seq ( seq int  NOT NULL AUTO_INCREMENT, id int, PRIMARY KEY (`seq`));
INSERT INTO seq ( id, seq )
    SELECT id, NULL FROM UsersTable ORDER BY points DESC;

UPDATE UsersTable INNER join seq ON UsersTable.id = seq.id SET UsersTable.rank = seq.seq;

 

Basically a temp table using an autonumber key, and inserting into that the id of the user ordered by the points. Then using that to do the update of the rank field in the users table.

 

All the best

 

Keith

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.