Hey everyone,
I am just adding a simple script that ranks people in terms of votes, which are stored in my mysql db as float (4,3). So if i want to find a users rank i can do a mysql query:
$queryv = "SELECT TUsers.* FROM TUsers WHERE FUsername='$user'";
$resultv = mysql_query($queryv) or die(mysql_error());
$totalvotes = mysql_numrows($resultv);
if($totalvotes>0)
{
$currentvotes=mysql_result($resultv,0,"FVotes");
}
$query = "SELECT TUsers.* FROM TUsers WHERE FVotes>'$currentvotes' ORDER BY FVotes DESC";
$result = mysql_query($query) or die(mysql_error());
$totalahead = mysql_numrows($result);
$totalahead (i thought!) would then be the number of people with more votes than that user, but when running the following query (with 4.091 extracted from the db as above):
SELECT TUsers.* FROM TUsers WHERE FVotes>'4.091' ORDER BY FVotes DESC, Fid DESC
I get the following:
user1(4.417)
user2 (4.167)
user3 (4.091)
user4 (4.091)
This obviously includes 2 records with 4.091 which are not > 4.091. I thought this might be to do with floating point precision (although at 3dp it seems unlikely) or incorrect casting. I tried is_float on currentvotes and it came back as not a float, but i don't really see why this would matter given you're using it in a mysql query?
I would really really appreciate it if someone with more wisdom than me could explain what i'm doing wrong as i don't understand it!
As ever thanks so much everyone,
Dave