<?
$tim2=microtime(1);
include_once 'inc/start_sess.php';
include_once 'inc/functions.php';
$num=1;
$q=mysql_query("SELECT * FROM `kolhoz_petground`");
while($pet=mysql_fetch_array($q))
{
if($num<500){
if($id==$pet['id_user']) continue; else {
$ul=mysql_fetch_array(mysql_query("SELECT `level` FROM `kolhoz_user`WHERE `id`='$pet[id_user]'"));
$up=mysql_fetch_array(mysql_query("SELECT `level` FROM `kolhoz_pet`WHERE `id`='$pet[id_pet]'"));
if($up['level']>$ul['level']){echo ''.$pet['id_user'].'<br/>';$num++;
$up=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_pet`WHERE `level`='$ul[level]'"));
if(!isset($up['id']))$up=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_pet`WHERE `level`='".($ul['level']-1)."'"));
if(!isset($up['id']))$ids=0; else $ids=$up['id'];
mysql_query("UPDATE `kolhoz_petground` SET `id_pet` = '$ids' WHERE `id_user` = '$pet[id_user]'");
}
$id=$pet['id_user'];

}
}
}
if($ku['id']==1)echo '<br/>'.$num.' #'.number_format(microtime(1)-$tim2,5).' сек. start#';
?>