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