I have a weird problem with my mysql query syntax.
I have made a system by which shows specific ranking to a user when they have certain amount of points.
For example
when they have 1000 or more points , they are level 1
3000 or more points , they are level 2
5000 or more points , they are level 3
8000 or more points , they are level 4
9000 or more points , they are level 5
Mysql table structure:
Table name: rank
structure: pts , rankname
mysql query as follows:
$result = mysql_query("SELECT * FROM rank WHERE pts <= '$userpts' ORDER BY pts DESC LIMIT 1")
or die(mysql_error());
$row = mysql_fetch_array($result);
if($row){
$rank = $row['rankname'];
echo $rank;
}
However a weird problem occurred, when a user points exceeds 10,000 points , they should get the rankname level 5 but instead they get the rankname level 1 (which user between 1000-2999 points gets)
Not sure what’s happening , they should get exactly level 5.
(P/S when user has 8500 points they get level 4 which means points below 10k works fine to get the ranknames)
Anything wrong with my query logic?
Im confused myself.
Make sure that the
ptsfield is a number field, not a CHAR or VARCHAR field.10000 as a number is larger than both 1000 and 9000. Strings, however, are compared according to their lexicographical sorting order (i.e., alphabetically), so then you get this order: