mattm1712 Posted November 6, 2011 Share Posted November 6, 2011 hi i have a table like this rank xp 1 0 2 50 3 100 4 200 say my username has 75xp how would a select which rank i am not sure how i can do this? :S cheers matt Quote Link to comment Share on other sites More sharing options...
haku Posted November 6, 2011 Share Posted November 6, 2011 switch(TRUE) { case $xp == 0: $rank = 1; break; case $xp <= 50: $rank = 2; break; case $xp <= 100: $rank = 3; break; case $xp <= 200: $rank = 4; break; } $rank will hold your rank. Quote Link to comment Share on other sites More sharing options...
xyph Posted November 6, 2011 Share Posted November 6, 2011 SELECT `rank` FROM `table` WHERE `xp` > $userXP ORDER BY `xp` DESC LIMIT 1 It orders the table from greatest to least XP, then returns the first rank it finds where xp is less than the XP entered. Quote Link to comment Share on other sites More sharing options...
mattm1712 Posted November 6, 2011 Author Share Posted November 6, 2011 it just echos Resource id #16 when i use the lastest reply Quote Link to comment Share on other sites More sharing options...
xyph Posted November 6, 2011 Share Posted November 6, 2011 You need to read up on using MySQL with PHP. You have to parse the result using a mysql_fetch or mysql_result function. 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.