<?

	$welbaner = mysql_query("SELECT
(SELECT COUNT(id) FROM tb_advbanclick where status='1') kolbaner,
(SELECT COUNT(id) FROM tb_advbanclick where pros='1' and status='1') kolpros");
$welbaner = mysql_fetch_assoc($welbaner);

if($welbaner['kolbaner']>=0){

       $welbanp = mysql_query("select * from tb_advbanclick where status='1' ORDER BY RAND()");
       $welbanp = mysql_fetch_assoc($welbanp);

       $idb=$welbanp['id'];
       $urlpic=$welbanp['urlpic'];
       $pocazov=$welbanp['pocazov'];
       $clicov=$welbanp['clic'];

       mysql_query("update tb_advbanclick set pros='1', pocazov='$pocazov'+1 where id='$idb' ");
       if($idb==""){$idb=0;$urlpic="/images/nobanner.gif";$clicov="0";$pocazov="0";}
}

if($welbaner['kolbaner']<=$welbaner['kolpros']){
mysql_query("update tb_advbanclick set pros='0'");
}

$idper = base64_encode($idb);
echo <<<HTML
<div align="center">
<font style="font-size:10px;"><a href="/go_ban.php?s={$idper}" target="_blank"><img src="{$urlpic}" border="0" width="468px" height="60px"></a>
<table style='width:468px; padding-top:5px;font-size:11px;'>
<tr>
<td aling='left' width="30%" style='font-size:10px;'><a href='bannersclick.php' style='color:#fff;'>» Посмотреть все</a></td>
<td style='font-size:10px;color:#fff;'> Показов: <b><font color="#fff">{$pocazov}</font></b>&nbsp;&nbsp;&nbsp;&nbsp;Кликов: <b><font color="#fff">{$clicov}</font></b></td>
<td aling='left' width="30%" style='font-size:10px;'><a href='/advertise.php?adv=bannerclick' style='color:#fff;'>» Разместить баннер</a></td>
</tr>
</table>
</div>
HTML;
?>