<?php
$query = "SELECT a.id, a.level, p.id, p.name, p.rank, p.country, (a.level/p.rounds*100) AS gmpr FROM player AS p, awards AS a WHERE a.id = p.id AND a.awd = '2051907' AND p.time > 360000 ORDER BY gmpr DESC LIMIT 5";

$query2 = "SET @n:=0";
$query3 = str_replace("FROM", ", @n:=@n+1 as num FROM", $query);
$query3 = str_replace("LIMIT 5", "", $query3);
?>