<?
$sql = "select * from tb_advban_300 where paused = 0 and modered = 1";
$res = mysql_query($sql);
$q = 0;
while ($row = mysql_fetch_array($res)) {
    if (intval($row['balance'] / $row['price']) == 0 or $row['balance'] < $row['price']) mysql_query("UPDATE tb_advban_300 SET paused = 1, balance = 0 WHERE id = '$row[id]'");
	$q++;
	$id[$q] = $row['id'];
	$banpic[$q] = $row['nametime'];
	$banformat[$q] = $row['typeban'];
}
if ($q == 0) {
    $banpict = "banners/noban_300.png";
    echo '<img src="/' . $banpict . '" width="200" height="300" border="0" />';
} else {
	$newi = rand(1,$q);
	$q = $newi;
	$banpict = "banners/" . $banpic[$q] . '.' . $banformat[$q];
    echo "<a href='/ban_url3.php?link=$id[$q]' target='_blank'><img src='/$banpict' width=200 height=300 border=0 /></a>";
}
?>