function get_rank($id){
$query = "SELECT user_id ".
"FROM user_prof ".
"ORDER BY exp DESC";
$result = mysql_query($query) or die (mysql_error());
$row = mysql_fetch_array($result) or die (mysql_error());
//loop to get rank of the user
$i = 0;
$num_row = mysql_num_rows($result);
while ($row['user_id'] != $id) {
if($i >= $num_row){
break;
}
$i++;
}
return $i;
}
see what I did is
1. get all data in the database
2. use a while loop in PHP find the place of an id(because all the data are fetched and ordered)
so I used PHP to find the place of the id
but can MySQL do it?
like return only where the id will locate if order in somekind of way?