Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Get the rank of a user in a score table, but rank only if a

Codes here !

Moderators: macek, egami, gesf

Get the rank of a user in a score table, but rank only if a

Postby nightkarnation » Wed Dec 04, 2013 3:27 pm

Hey guys,

Here's a simplified table...



    Name | Score| Type |
    -------------------------------------------
    Gustavo |10 | VsStory |
    John |22 | VsRandom|
    test |3 | VsStory |



Here's a working query to only get the ranking of a specific user based on his score...

Code: Select all
SELECT 1 + (SELECT count( * ) FROM highscores a WHERE a.score > b.score ) AS rank FROM
highscores b WHERE Name = 'Gustavo' AND Type = 'VsStory' ORDER BY rank LIMIT 1 ;


but the problem I am having is that the column called Type is not respecting the Type = 'VsStory' ... for example in this query, Gustavo gives a rank value of 2...when it should be 1... for some reason Type column is not being processed to only count the VsStory values and not all the rows disregarding if its VsStory or VsRandom...



Any ideas??



Thanks a lot in advance!
nightkarnation
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue Jun 26, 2012 10:48 am

Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.