$sp=mysql_query('SELECT `id`,`level`,`name` FROM `clan`');
while($pl=mysql_fetch_array($sp)){
$timday=time()-86400;
$xu=mysql_fetch_array(mysql_query('SELECT COUNT(`id`) FROM `users` WHERE `clan` = "'.$pl['id'].'" AND `admin` = 0 AND `online` > "'.$timday.'" AND `real` = 1 LIMIT 1'));
$xu=$xu[0];
$clanw=mysql_fetch_array(mysql_query('SELECT COUNT(`id`) FROM `battle` WHERE `type` = 250 AND `time_over` > "'.$timday.'" AND ((`team_win`=1 AND `clan1` = "'.$pl['id'].'") OR (`team_win`=2 AND `clan2` = "'.$pl['id'].'")) LIMIT 1'));
$clanw=$clanw[0];
$clanl=mysql_fetch_array(mysql_query('SELECT COUNT(`id`) FROM `battle` WHERE `type` = 250 AND `time_over` > "'.$timday.'" AND ((`team_win`=2 AND `clan1` = "'.$pl['id'].'") OR (`team_win`=1 AND `clan2` = "'.$pl['id'].'")) LIMIT 1'));
$clanl=$clanl[0];
//$st = mysql_fetch_array(mysql_query('SELECT SUM(`val`) AS `exp` FROM `users_reting` WHERE `clan` = "'.$pl['id'].'" LIMIT 1'));
$st=mysql_fetch_array(mysql_query('SELECT `exp` FROM `clan` WHERE `id` = "'.$pl['id'].'" LIMIT 1'));
$wn=mysql_fetch_array(mysql_query('SELECT SUM(`win`) AS `win` , SUM(`lose`) AS `lose` , SUM(`nich`) AS `nich` FROM `users` WHERE `clan` = "'.$pl['id'].'" LIMIT 1'));
$rl=mysql_fetch_array(mysql_query('SELECT `exp`,`global`,`exp_real`, `win`,`lose` FROM `aaa_clan_reting_list` WHERE `clan` = "'.$pl['id'].'" ORDER BY `id` DESC LIMIT 1'));
$exp_list[$pl['id']]=$st['exp'];
$log_list[$pl['id']]=$pl['name'];
$level_list[$pl['id']]=$pl['level'];
$win_list[$pl['id']]=$wn['win'];
$lose_list[$pl['id']]=$wn['lose'];
$nich_list[$pl['id']]=$wn['nich'];
$xu_list[$pl['id']]=$xu;
$add_exp=0;
if(date('d')==1)
{
$global_exp=0;
}
else
{
$global_exp=round($rl['global']);
}
//$xul = mysql_query('SELECT `level` FROM `users` WHERE `clan` = "'.$pl['id'].'" AND `admin` = 0 AND `real` = 1 LIMIT 1');
$xul=mysql_query('SELECT `st`.`repexp`,`st`.`id` FROM `users` AS `u` LEFT JOIN `stats` AS `st` ON (`u`.`id` = `st`.`id`) WHERE `u`.`clan`="'.$pl['id'].'"');
while($xull=mysql_fetch_array($xul))
{
$add_exp=$add_exp+$xull['repexp'];
mysql_query('UPDATE `stats` SET `repexp` = 0 WHERE `id` = "'.$xull['id'].'" LIMIT 1');