<?php
$query = "SELECT id,name,rank,(skillscore+cmdscore+teamscore)/(time/60) as spm,country FROM player WHERE time > 36000 AND time < 360000 ORDER BY spm DESC LIMIT 5";

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