There is a script that opens the entire user table, then sorts it by field and gives the number in the rating:
function num_tasks_rate($a) { $query = mysql_query("SELECT `vk_id` FROM `users` WHERE `ban` != 2 ORDER BY `tasks_summ_done` DESC"); for($i = 1; $i <= $data_rates = mysql_num_rows($query); $i++) { $data_rates = mysql_fetch_array($query); if($data_rates['vk_id'] == $a) { $n = $i; break; } } return $n; }
But such a code loads the system very much, apparently because it opens 20,000 users. How can you optimize or write differently?