grant09 Posted March 3, 2011 Share Posted March 3, 2011 ok i have been at this for about 3 days now just cant seem to get it to work ranked in my game well when you go to halloffame it tells you wot your rank is well i want my rank to tell me wot i rank in the game for Strength in my gym so if i was ranked 3 in my game it wld say 3 in all the game and so on for speed ect.. any help wld be great this is wot am workin with $result= mysql_query("SELECT * FROM `grpgusers` ORDER BY `grpgusers`.`strength` DESC LIMIT 0 , 1"); while($line3 = mysql_fetch_array($result, MYSQL_BOTH)) { any help thanks Quote Link to comment Share on other sites More sharing options...
btherl Posted March 3, 2011 Share Posted March 3, 2011 Try changing the limit to 2, 1. But that won't take into account if some users have the same strength. Quote Link to comment Share on other sites More sharing options...
grant09 Posted March 3, 2011 Author Share Posted March 3, 2011 Strength ........i have got most stats in the game sorry my english is not good but i am ranked 3 1,033,485 Ranked 3 Quote Link to comment Share on other sites More sharing options...
fenway Posted March 3, 2011 Share Posted March 3, 2011 Well wn i done that its saying am ranked 2 but am the stongers with strenght That's not English. Quote Link to comment Share on other sites More sharing options...
btherl Posted March 4, 2011 Share Posted March 4, 2011 Do you want to find the user with the 3rd highest strength? Eg User A: Strength 100 User B: Strength 90 User C: Strength 85 <-- this one User D: Strength 80 And is strength stored in the grpgusers table as "strength"? Quote Link to comment Share on other sites More sharing options...
grant09 Posted March 4, 2011 Author Share Posted March 4, 2011 strength 100000 <----highest 10000 0000 000 00 0<---- lowest if the user is 1000000 in strength and he has the most in the game he would be ranked 1 in the game 0 this user would be the lowest in the game and he would be ranked last so if there is 37 users he would be ranked 37 and i want to display the number they are ranked in the game so the strongest would be ranked 1 Quote Link to comment Share on other sites More sharing options...
btherl Posted March 4, 2011 Share Posted March 4, 2011 You could do: $result= mysql_query("SELECT * FROM `grpgusers` ORDER BY `grpgusers`.`strength` DESC"); $rank = 1; while($line3 = mysql_fetch_array($result, MYSQL_BOTH)) { print "Rank $rank: "; # Display data from $line3 $rank = $rank + 1; } $rank will increase by 1 each time through the loop. Quote Link to comment Share on other sites More sharing options...
grant09 Posted March 4, 2011 Author Share Posted March 4, 2011 no its not showing the user wot he ranked its says am ranked 1 but so are all the other users Quote Link to comment Share on other sites More sharing options...
btherl Posted March 4, 2011 Share Posted March 4, 2011 Please post your current code Quote Link to comment Share on other sites More sharing options...
grant09 Posted March 4, 2011 Author Share Posted March 4, 2011 <? $result= mysql_query("SELECT * FROM `grpgusers` ORDER BY `grpgusers`.`strength` DESC LIMIT 0 , 30"); while($line3 = mysql_fetch_array($result, MYSQL_BOTH)) { echo "<tr><td width='17%' align='center'><font color='#00BFFF'>".$line3['id']."</font></td></tr>"; ?> Quote Link to comment Share on other sites More sharing options...
btherl Posted March 4, 2011 Share Posted March 4, 2011 You could do: $result= mysql_query("SELECT * FROM `grpgusers` ORDER BY `grpgusers`.`strength` DESC"); $rank = 1; while($line3 = mysql_fetch_array($result, MYSQL_BOTH)) { print "Rank $rank: "; # Display data from $line3 $rank = $rank + 1; } $rank will increase by 1 each time through the loop. In the post above I added a variable $rank. This tells you what rank each user is. Quote Link to comment Share on other sites More sharing options...
grant09 Posted March 4, 2011 Author Share Posted March 4, 2011 yes i see that but how do i just get the single users rank so only he can see wot he is ranked in the game sorry am been a pain Quote Link to comment Share on other sites More sharing options...
btherl Posted March 4, 2011 Share Posted March 4, 2011 You can make the list of all the users, then find where the single user is in the list. Have you used arrays before? Quote Link to comment Share on other sites More sharing options...
grant09 Posted March 4, 2011 Author Share Posted March 4, 2011 no how would i single all those user out to get there rank Quote Link to comment Share on other sites More sharing options...
fenway Posted March 5, 2011 Share Posted March 5, 2011 There are countless blog posts on this kind of thing. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 5, 2011 Share Posted March 5, 2011 You could do it is 2 queries: set @strength = (select strength from grpgusers where user_id = 3); select count(*) as rank from grpgusers where strength >= @strength; or select count(*) as rank from grpgusers where strength >= (select strength from grpgusers where user_id = 3); Quote Link to comment Share on other sites More sharing options...
grant09 Posted March 5, 2011 Author Share Posted March 5, 2011 sorry am still new to php and confussed about wot would the output be to show the ranks Quote Link to comment Share on other sites More sharing options...
fenway Posted March 6, 2011 Share Posted March 6, 2011 sorry am still new to php and confussed about wot would the output be to show the ranks HuH/ Quote Link to comment Share on other sites More sharing options...
grant09 Posted March 16, 2011 Author Share Posted March 16, 2011 ok sorry about the wait am just back from holiday ok i will try explain how i want to to show 1 200100675456 <<<-- jeffy i Want on his profile to say .....you are ranked [1] with out the row of other numbers so its just an individual number like[1] 2 484918 3 210000 4 101000 5 25500 6 2651 7 1000 8 335 9 295 10 255 11 130 12 79 13 10 <<<- jimmy i Want on his profile to say he is ranked [13] in all of my game but the code that am trying to do this is not giving me that sum its giving me am ranked 2 and so are all the users Quote Link to comment Share on other sites More sharing options...
fenway Posted March 17, 2011 Share Posted March 17, 2011 Did you try the queries you where given? Quote Link to comment Share on other sites More sharing options...
grant09 Posted March 18, 2011 Author Share Posted March 18, 2011 yes but its giving me the same rank on all users Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 19, 2011 Share Posted March 19, 2011 The code I gave above works perfectly on my database. are you getting the same rank because your not changing the user id that is at the end of the query? Quote Link to comment Share on other sites More sharing options...
grant09 Posted March 21, 2011 Author Share Posted March 21, 2011 select count(*) as rank from grpgusers where strength >= (select strength from grpgusers where id = $user_class->id); that the way i have tryed it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.