<?PHP
if (!defined('beerman')) {exit();}
$res=mysql_query("SELECT * from `tb_advban` WHERE `paused`='0' AND `modered`='1' AND `typeban`='1' ORDER BY RAND()");
$i=0;
while($row=mysql_fetch_array($res)){
if(intval($row["balance"]/$row["price"])=="0" or $row["balance"] < $row["price"]) mysql_query("UPDATE `tb_advban` SET `paused` = '1',`balance` = '0' WHERE `id` = '".$row["id"]."'");
	$i++;
	$id[$i]=$row["id"];
	$url_img = $row["url_img"];
}
if($i==0){
echo "<a href='http://".$_SERVER["HTTP_HOST"]."/addbanner.html' target='_blank'><img src='http://".$_SERVER["HTTP_HOST"]."/banners/ban468.png' width='468' height='60'></a>";
}else{
echo "<a href='/ban-link-".$id[$i].".html' target='_blank'><img src='$url_img' width='468' height='60'></a>";
}
?>