Posted by cvanschalkwijk on 02/23/06 21:52
If you have the pkey at the start of this, you can just generate rank
and get the total pretty easily on the fly. Of course this require's
MySQL 5 w/ nested query support. This way you aren't messing with your
records and if you insert or update your database it will generate
everyone's rank accurately on the fly when it is requested. Index your
total field and you should be fine even for large databases.
$result = mysql_query("SELECT total, (COUNT( * ) +1) AS rank FROM
quiz_percentile WHERE total > ( SELECT total FROM quiz_percentile WHERE
pkey =$id )")'
while($myrow=mysql_fetch_array($result))
{
$myRank = $myrow["rank"];
$myTotal = $myrow["total"];
}
echo "Your total is $myTotal your rank is $myRank and your pkey is
$id";
- Clay
Navigation:
[Reply to this message]
|