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 Link to comment https://forums.phpfreaks.com/topic/250571-help-with-ranking-system-selecting-a-rank-between-2-values/ 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. Link to comment https://forums.phpfreaks.com/topic/250571-help-with-ranking-system-selecting-a-rank-between-2-values/#findComment-1285659 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. Link to comment https://forums.phpfreaks.com/topic/250571-help-with-ranking-system-selecting-a-rank-between-2-values/#findComment-1285661 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 Link to comment https://forums.phpfreaks.com/topic/250571-help-with-ranking-system-selecting-a-rank-between-2-values/#findComment-1285671 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. Link to comment https://forums.phpfreaks.com/topic/250571-help-with-ranking-system-selecting-a-rank-between-2-values/#findComment-1285675 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.