Posted by Kapil Jain on 02/18/06 07:42
Dear All,
I have score table in which i am storing scores for online quiz
what i want is to allot rank to all candidates as per their scores
for that i applied logic that i sorted table order by net score in desc
order
and assigned variable $i++ in place rank correponding to pkey of that
row
so in this manner person who is having net score 10 would get rank 1
and so on.
but what i want is if some scorer will get same score say 5 than in
this case he should both should get rank 5 but in this point my
variable $i++ will allot different rank for same scorer viz 5 and 6 so
i want rank would remain same for same score.
Please help me urgently....
below is the test code
<? include("libFunctions.php");
connectDb();
session_start(); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<?
if (!isset($submit))
{
$sql ="select pkey,total from `quiz_percentile` order by total desc"
;
$percentile = mysql_query($sql) or die (mysql_error());
$i=0;
while ($rs = mysql_fetch_array($percentile))
{
//echo $rs["total"]."This is total"."<br>";
$i++;
//echo $i."<br>";
$sql_insert = "update quiz_percentile set rank='".$i."' where
pkey='".$rs["pkey"]."' order by total desc";
//echo $sql_insert."<br>";
$arr = mysql_query($sql_insert) or
die(disp_message(mysql_error(),"javascript:history.back()"));
if($rs["total"]/$rs["total"]=1)
{
//echo "This is matching<br>";
echo ($rs["total"]=$rs["total"])."<br>";
}
}
}
?>
</body>
</html>
[Back to original message]
|