Hi all
I have recently watched a tutorial series from PHPACADEMY called the advert rotation script series.
I have found a small problem, the problem is that if any of the adverts have expired then the rest will not show.
does anyone have any solutions for this issue, that if 1 or more have expired the active adverts will still run.
Code:
ADS main code
<?php
include 'db.inc.php';
$ads = mysql_query("Select `advert_id`, `image` FROM `ads` WHERE UNIX_TIMESTAMP() < `expires` AND `shown`=0 ORDER BY `advert_id` ASC LIMIT 1");
while ($ads_row = mysql_fetch_assoc($ads)) {
$advert_id = $ads_row['advert_id'];
$image = $ads_row['image'];
echo '<a href="go.php?advert_id='.$advert_id.'" target="_blank"><img src="'.$image.'" /></a>';
mysql_query("UPDATE `adverts` SET `shown`=1, `imprssions`=`impressions`+1 WHERE `advert_id`=$advert_id");
$shown = mysql_query("SELECT COUNT(`advert_id`) FROM `ads` WHERE `shown`=0");
if (mysql_result($shown, 0) == 0) {
mysql_query("UPDATE `adverts` SET `shown`=0");
}
}
?>
the db.inc.php is just the database connection file.
DB Structure:
advert_id int(11) primary auto incrament
image varchar 255
url varchar 255
impressions int(11)
clicks int(11)
expires int(11)
shown int(1)
thanks