CanMan2004 Posted September 27, 2006 Share Posted September 27, 2006 Hi allI have a simple game which is storing users details who play in, in a sql database, I also store the score that the user has got from paying the game.The query I use to insert the data from the game to the sql database is[code]$query = "INSERT INTO usersscores (fullname, email, score) VALUES ('$fullname', '$email', '$score');";mysql_query($query);[/code]What I want to do, is to run a query after the insert query shown above, which will show the user what score position they are. For example, if the database had 4 rows and looked like23.2334.5445.3265.22and the users score was 29.87, then the query would run and return them as the 2nd highest score, again, if there score was 90.43, it would return as the 5th highest scorer.Is this possible?Thanks in advance for any helpEdMy query is Quote Link to comment https://forums.phpfreaks.com/topic/22260-counting-result/ Share on other sites More sharing options...
ober Posted September 27, 2006 Share Posted September 27, 2006 SELECT * FROM usersscores ORDER BY score LIMIT 1,5;That would list them in order (1-5). Quote Link to comment https://forums.phpfreaks.com/topic/22260-counting-result/#findComment-99686 Share on other sites More sharing options...
Orio Posted September 27, 2006 Share Posted September 27, 2006 SELECT COUNT(*) FROM usersscore WHERE score<'$score'This will count how many people have a score that is lower (better) than $score.If you want to output the rank, add 1 to the result.Orio. Quote Link to comment https://forums.phpfreaks.com/topic/22260-counting-result/#findComment-99689 Share on other sites More sharing options...
CanMan2004 Posted September 27, 2006 Author Share Posted September 27, 2006 Thank you Quote Link to comment https://forums.phpfreaks.com/topic/22260-counting-result/#findComment-99694 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.