Jump to content

[SOLVED] creating a rank field, but decrementing values


PC Nerd

Recommended Posts

im creating a webgame, and when i create a new account.... i want to make that new account the lowest rank.  how would i do that??? like l8a in the gazme, your rank woul dbe determined and chenged according to how you are going, but when you begin in the game........your the least experienced, also the lowest rank????
Link to comment
Share on other sites

well basicaly i need a way to find the highest number in the rank field, and make the new record equal ++1 to that rank.  i cant just set a rank when they sign up.... because their rank will change according their activeness and scores on the site.... so it has to start off as the lowest rank and then itll be changed
Link to comment
Share on other sites

well if there are 10 users in total, then the lowest rank will be 10, and the highest rank will be 1.  what i want to do is: eg

add an 11th user.  but how would i create his rank to be the lowest, if i dont know the current lowest.  what sort of query or code would i need.??

sorry about not explaining as well as i could have

PC Nerd
Link to comment
Share on other sites

If you dont know the current lowest then its impossible. You still need to be alot clearer in your explination, but the logic is a simple as querying your currents ranks for the lowest, once you have the lowest, take one from it to make the new value the lowest.

I think half the problem in your explination is your wording. For instance, common math states that 10 is [b]higher[/i] then 1.
Link to comment
Share on other sites

yes i agree with you in maths..... but is the winners not 1'st, and the last not 10'th??? lol

so were looking for the highest number( ie lowest rank)

i definately want that to be the way that its stored, decauase that determins in what order they are displayed in a different secteion of the website.

thanks for your help everyone
Link to comment
Share on other sites

ok, i think that if a make a query that finds the total number of records in the General_Stats table, then made the new record rank that query output number +1, would make the new record the lowest rank according the logic that was stated above.?????  but my question is.... what query would this be? i want to find the length of the database really?,, can anyone help with this
Link to comment
Share on other sites

0 is always lowest. If they've just joined, they have no rank at all. As they gain rank, update it to go higher. Then when you list them, THEN you reverse the numbers so the person with the highest (say 1473) is 1, and the next (1247) is 2, etc.
Link to comment
Share on other sites

well that would be too hard to do, becauase your always getting new members..... so one day the 1456 record might be first, but the next might be 1467 is the first rank.  what i want to do is retreive the total number of records in the table and store it as an integer, how do i do that???
Link to comment
Share on other sites

ok, here is my my idea, if you dont understand.....

10 users already

U1
U2
U3
U4
U5
U6
U7
U8
U9
U10

of the rank

1. U1
2. U2
3. U3
4. U4
5. U5
6. U6
7. U7
8. U8
9. U9
10. U10



WITHIN A WEEK IT LOOKS LIKE THIS:



1. U2
2. U3
3. U5
4. U4
5. U1
6. U8
7. U6
8. U7
9. U10
10. U9


now if i create a new user, i want him to have the lowest rank, ie 11.    and the new user being U11


1.  U2
2.  U1
3.  U3
4.  U4
5.  U9
6.  U6
7.  U5
8.  U7
9.  U8
10.  U10
11.  U11



so as always, the new user will be the lowest rank, until they are active on the website and then they earn like points to raise the rank




so the lowest rank, will the the total number of records in the table (ie the number of users) so the new player will be the total number of users, +1



i hope this helps


Link to comment
Share on other sites

The best way to do what you are trying to accomplish is to store the current amount of registered players in a sql table so if you have 123 people then it will be 123.

Then when someone signs up, fetch that number, and add 1 to it, and set there rank to that. And also set the stored number to that, so that it will always be up to date.

Another way is to run a query to check how many rows there are in a table (1 for each player) and add 1 to that and use that for their rank. Then you won't have to have the number written down anywhere, but this way is much slower, it will take a lot longer, and could bring your server to it's knees if there ends up being a lot of members.
Link to comment
Share on other sites

You could store their POINTS instead of their rank, and then have your code determine the rank. So a user STARTS at 0, and as they gain points, you store their POINTS.

Then when you want to calculate the ranks, you select them ordered by the POINTS.
Link to comment
Share on other sites

thanks, that thread is a great help..... can i just ask.... does the mysql_num rows.... a) contact a mysql v5 or does it need to be mysqli_num_rows....... and b) does it return an integar or something similar, so you could go like..... ( using the therad as the base example)


[code]

$ranks = mysqli_num_rows($query);

$New_P:layer_Rank = $ranks +1;

[/code]


would that work....?


thanks for all you help
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.