I've been working on a small script to rotate adverts around aswell as recording how many times they've been viewed. This is working fine but what I'm trying to do now is if there is no ads to display or no active ones it will display my AdSense.
I've tried a few things which I thought should've worked but here's my code now:
[code=php]
<?
$bannerquery = "SELECT * FROM banner WHERE active='T' ORDER BY Rand() LIMIT 1";
$bannerresult = mysql_query($ba nnerquery);
while ($brow = mysql_fetch_arr ay($bannerresul t)) {
$bannerid = $brow[0];
$bannerimage = $brow[2];
$bannerhref = $brow[1];
$banneralt = $brow[3];
$bannerhits = $brow[4];
if($bannerid != "")
{
echo "<a href=\"$bannerh ref\" target=\"_blank \"><img src=\"images/banners/$bannerimage\" alt=\"$banneral t\" /></a>";
/*Update Impressions*/
$newhits = $bannerhits + 1;
$bannerinsert = "UPDATE banner SET hits='$newhits' WHERE id='$bannerid'" ;
mysql_query($ba nnerinsert);
}
else
{
echo "<script type=\"text/javascript\"><!--
google_ad_clien t = \"pub-*************** **\";
google_ad_width = 728;
google_ad_heigh t = 90;
google_ad_forma t = \"728x90_as\ ";
google_ad_type = \"text_image \";
google_ad_chann el = \"\";
google_color_bo rder = \"CCCCCC\";
google_color_bg = \"CCCCCC\";
google_color_li nk = \"333333\";
google_color_te xt = \"000000\";
google_color_ur l = \"333333\";
//-->
</script>
<script type=\"text/javascript\"
src=\"http://pagead2.googles yndication.com/pagead/show_ads.js\">
</script>";
}
}
?>
[/code]
What this is doing is when there is ads to display it displays them as it should, when there's no ads or active ads to display it shows nothing instead of the adsense code.
Also, is there a simple way of implementing a system to also record how many times it has been clicked (I know it's possible, just not sure how complicated it is)?
Thanks for any help :)
I've tried a few things which I thought should've worked but here's my code now:
[code=php]
<?
$bannerquery = "SELECT * FROM banner WHERE active='T' ORDER BY Rand() LIMIT 1";
$bannerresult = mysql_query($ba nnerquery);
while ($brow = mysql_fetch_arr ay($bannerresul t)) {
$bannerid = $brow[0];
$bannerimage = $brow[2];
$bannerhref = $brow[1];
$banneralt = $brow[3];
$bannerhits = $brow[4];
if($bannerid != "")
{
echo "<a href=\"$bannerh ref\" target=\"_blank \"><img src=\"images/banners/$bannerimage\" alt=\"$banneral t\" /></a>";
/*Update Impressions*/
$newhits = $bannerhits + 1;
$bannerinsert = "UPDATE banner SET hits='$newhits' WHERE id='$bannerid'" ;
mysql_query($ba nnerinsert);
}
else
{
echo "<script type=\"text/javascript\"><!--
google_ad_clien t = \"pub-*************** **\";
google_ad_width = 728;
google_ad_heigh t = 90;
google_ad_forma t = \"728x90_as\ ";
google_ad_type = \"text_image \";
google_ad_chann el = \"\";
google_color_bo rder = \"CCCCCC\";
google_color_bg = \"CCCCCC\";
google_color_li nk = \"333333\";
google_color_te xt = \"000000\";
google_color_ur l = \"333333\";
//-->
</script>
<script type=\"text/javascript\"
src=\"http://pagead2.googles yndication.com/pagead/show_ads.js\">
</script>";
}
}
?>
[/code]
What this is doing is when there is ads to display it displays them as it should, when there's no ads or active ads to display it shows nothing instead of the adsense code.
Also, is there a simple way of implementing a system to also record how many times it has been clicked (I know it's possible, just not sure how complicated it is)?
Thanks for any help :)
Comment