473,382 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Rotator - Problem with Adsense and Else

73
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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?
  3.    $bannerquery  = "SELECT * FROM banner WHERE active='T' ORDER BY Rand() LIMIT 1";
  4.    $bannerresult = mysql_query($bannerquery);
  5.  
  6.  
  7.    while ($brow = mysql_fetch_array($bannerresult)) {
  8.       $bannerid = $brow[0];
  9.       $bannerimage = $brow[2];
  10.       $bannerhref = $brow[1];
  11.       $banneralt = $brow[3];
  12.       $bannerhits = $brow[4];
  13.  
  14.        if($bannerid != "")
  15.    {
  16.  
  17.       echo "<a href=\"$bannerhref\" target=\"_blank\"><img src=\"images/banners/$bannerimage\" alt=\"$banneralt\" /></a>";
  18.  
  19.       /*Update Impressions*/
  20.       $newhits = $bannerhits + 1;
  21.       $bannerinsert = "UPDATE banner SET hits='$newhits' WHERE id='$bannerid'";
  22.       mysql_query($bannerinsert);
  23.    }
  24.  
  25. else
  26. {
  27. echo "<script type=\"text/javascript\"><!--
  28. google_ad_client = \"pub-*****************\";
  29. google_ad_width = 728;
  30. google_ad_height = 90;
  31. google_ad_format = \"728x90_as\";
  32. google_ad_type = \"text_image\";
  33. google_ad_channel = \"\";
  34. google_color_border = \"CCCCCC\";
  35. google_color_bg = \"CCCCCC\";
  36. google_color_link = \"333333\";
  37. google_color_text = \"000000\";
  38. google_color_url = \"333333\";
  39. //-->
  40. </script>
  41. <script type=\"text/javascript\"
  42.   src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">
  43. </script>";
  44. }
  45. }
  46. ?>
  47.  
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 :)
Jul 20 '07 #1
6 1536
Jeigh
73
Also, would somthing like what I've done be easily modified to be able to show ads that have scripts?

Thanks again.
Jul 21 '07 #2
pbmods
5,821 Expert 4TB
Heya, Jeigh.

Is your script outputting anything? Perhaps this line:
Expand|Select|Wrap|Line Numbers
  1. if($bannerid != "")
is not checking for the correct value. Try using empty() instead.
Jul 21 '07 #3
pbmods
5,821 Expert 4TB
In terms of counting clicks, simply have the link go to an intermediate page that registers the click and then redirects the browser to the target page.
Jul 21 '07 #4
Jeigh
73
Thank you very much for your reply, I used empty instead but it still didn't work, so I also tried moving the end bracket for the while to here:

Expand|Select|Wrap|Line Numbers
  1.    while ($brow = mysql_fetch_array($bannerresult)) {
  2.       $bannerid = $brow[0];
  3.       $bannerimage = $brow[2];
  4.       $bannerhref = $brow[1];
  5.       $banneralt = $brow[3];
  6.       $bannerhits = $brow[4];
  7.       } /*<------*/
  8.  
Instead of it being around the whole script and it worked :)

For the clicks, I'm assuming you mean have the link be <a href="clicks.php"> and within that have somthing like:

Expand|Select|Wrap|Line Numbers
  1. mysql_query("UPDATE banners SET clicks='$newclicks' WHERE id='$bannerid'");
  2.  
  3. header(Location: $url);
  4.  
But how will I get the value for $bannerid to stay the same when it goes to clicks.php as I assume it will just randomly choose another ad from the database.

Thanks.
Jul 21 '07 #5
Jeigh
73
Never crossed my mind to put the values into the URL until now but I've got it all sorted and it's recording the clicks and redirecting to the site. I used:

Expand|Select|Wrap|Line Numbers
  1.       echo "<a href=\"redirect.php?bannerid=$bannerid&href=$bannerhref\" target=\"_blank\"><img src=\"images/banners/$bannerimage\" alt=\"$banneralt\" /></a>";
  2.  
and on redirect.php:

Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3. mysql_connect(localhost, *******, *******) or die(mysql_error());
  4. $dbname = '********';
  5. mysql_select_db($dbname) or die(mysql_error());
  6.  
  7. session_start();
  8.  
  9. $bannerid= trim($_GET['bannerid']);
  10.  
  11. $bannerhref= trim($_GET['href']);
  12.  
  13. $clicks = mysql_query("SELECT clicks FROM banner WHERE id='$bannerid'");
  14.  
  15. while($clickfetch = mysql_fetch_array($clicks))
  16. {
  17. $oldclicks = $clickfetch[0];
  18. }
  19.  
  20. $newclicks = $oldclicks + 1;
  21.  
  22. mysql_query("UPDATE banner SET clicks='$newclicks' WHERE id='$bannerid'");
  23.  
  24. header("Location: $bannerhref");
  25.  
  26. ?>
  27.  
  28.  
Thanks for the help :)
Jul 21 '07 #6
pbmods
5,821 Expert 4TB
Heya, Jeigh.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Jul 21 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Carolyn Gill | last post by:
It was working fine on the test server. loaded it onto iis6 server after installing php and got everything working (after redirecting it to the correct directory) except for 1 annoying error that I...
1
by: jonathanthio | last post by:
How do I create a page rotator? Is there a script for that? Also is there a way to do a page rotator that's not random but based on cookies. For example, if a new person see my website, it'll...
4
by: Leon | last post by:
I need an ad management system that record impressions and clicks as well as display gif, jpeg, and flash banners. I don't mind trying to build it myself, but I'm kind of press for time. do anyone...
2
by: Bredahl jensen | last post by:
Hello, Where can i find a dynamic content rotator. The asp.net server control only show the next content when page has refreshed. But this is boring to me. I'm not the javascript /dhtml expert...
3
by: Mark A. Sam | last post by:
Hello, Does anyone know of a third party ad rotator that automatically changes the images? It seems like the ad rotator in that comes with Visual Web Developer changes images only when the...
0
by: Mat | last post by:
ASP:Rotator It would be nice to have an expire date in the XML input to the banner rotator. so you dont have to remove an entry to it at a certain date
2
by: kwenterprise | last post by:
Hello All, I am normally great at figuring out ways around iframe issues that frustrate us all. I am using javasript to try and break an iframe that I have a banner rotator embedded in but it...
2
by: Excel 009 | last post by:
Hi All, I have the appended code which I used for a banner rotator. It works great except that there 1. there is a border which I do not want and 2. on top of the banner there is a black bar...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.