Current location: Hot Scripts Forums » Programming Languages » PHP » Rotating Ads Help


Rotating Ads Help

Reply
  #1 (permalink)  
Old 05-03-08, 04:11 PM
DieuxSoldat_04 DieuxSoldat_04 is offline
Newbie Coder
 
Join Date: May 2008
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Rotating Ads Help

Hello PT Community,

I already did quite a few searches on these forums and I did not find what I was searching for so I decided to post my question.

I am trying to find a way to display a different ad in the same spot with same dimension, upon each refresh. I am using HTML for the web site and we have a few different codes for the ads. Here are two examples:

Javascript Code:
  1. <script type="text/javascript"><!--
  2. google_ad_client = "pub-8412003942395982";
  3. /* 468x60, created 4/23/08 */
  4. google_ad_slot = "6187880626";
  5. google_ad_width = 468;
  6. google_ad_height = 60;
  7. google_cpa_choice = ""; // on file
  8. //-->
  9. </script>

Javascript Code:
  1. <script type="text/javascript">
  2. AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0','width','160','height','600','src','http://www.Counter-Strike.com/affiliate/banners/cs-flash_160x600?actionURL=http://www.Counter-Strike.com/affiliate/idevaffiliate.php?id=2477_5_1_19','quality','high','pluginspage','http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash','movie','http://www.Counter-Strike.com/affiliate/banners/cs-flash_160x600?actionURL=http://www.Counter-Strike.com/affiliate/idevaffiliate.php?id=2477_5_1_19' ); //end AC code
  3. </script>

They seem to be different codes though they are both Java Scripts. I don't know how I would put about 7 of them on a rotation to display a new one on each page view/refresh. Can someone please help me?

Thanks!
Sincerely,
Jason H.

Last edited by UnrealEd; 05-03-08 at 04:32 PM. Reason: please use the proper syntax highlighters
Reply With Quote
  #2 (permalink)  
Old 05-03-08, 10:54 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Sorry, you wanted Javascript.
I don't think it can be done with HTML or even with HTML & Javascript.
You need a server side scripting language, like PHP.
There is no way to store values in Javascript variables.
Because they get reset when the page is refreshed.

Now if you just wanted to rotate adds while viewing the page, then that can be done with Javascript.
__________________
Jerry Broughton

Last edited by job0107; 05-03-08 at 11:10 PM.
Reply With Quote
  #3 (permalink)  
Old 05-03-08, 11:18 PM
DieuxSoldat_04 DieuxSoldat_04 is offline
Newbie Coder
 
Join Date: May 2008
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
I am totally ok with PHP. I am just less advanced with PHP thus I wanted to steer clear of it. If people are willing to walk me through or point me in the right direction, I am up for anything. Please continue with PHP!

Thanks!
Jason H.
Reply With Quote
  #4 (permalink)  
Old 05-03-08, 11:28 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Here is an easy solution using PHP.

I use a session variable to hold the rotation count and a SWITCH to do the rotating.
PHP Code:

<?php
session_start
();
$_SESSION["counter"]=!empty($_SESSION["counter"])?$_SESSION["counter"]:0;
$_SESSION["counter"]++;
switch(
$_SESSION["counter"])
{
 case 
1:
?>
  <div>
   Place first add here
  </div>
  <?php
  
break;
 case 
2:
 
?>
  <div>
   Place second add here
  </div>
  <?php
  
break;
 case 
3:
 
?>
  <div>
   Place third add here
  </div>
  <?php
  
break;
 default:
 
?>
  <div>
  Place last add here
  </div>
  <?php
  $_SESSION
["counter"]=0;
 }
?>
You can add as many case's to the SWITCH as you need.
Just make sure the default: is at the end so it can reset the counter.

I have session_start(); at the top of this page. If you plan on putting this SWITCH somewhere in the middle of your HTML code, then put the session_start() at the very top of the page.
Like this:
PHP Code:

<?php
session_start
();
$_SESSION["counter"]=!empty($_SESSION["counter"])?$_SESSION["counter"]:0;
$_SESSION["counter"]++;
?>
__________________
Jerry Broughton

Last edited by job0107; 05-03-08 at 11:42 PM.
Reply With Quote
  #5 (permalink)  
Old 05-04-08, 03:36 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Very nice code Jerry
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #6 (permalink)  
Old 05-04-08, 03:46 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
Using an array makes the code even better: you can get rid of the entire switch statement, and makes it easier to add data if you want to use a database or flatfile in which you store the adds
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #7 (permalink)  
Old 05-04-08, 03:55 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by UnrealEd View Post
Using an array makes the code even better
I'd agree in most circumstances, however as DieuxSoldat_04 quite clearly wants as little php code as possible because of lack of understanding, I think this is a great solution. It's simple, yet works perfectly for what he needs. If the file has say 400 ads, obviously you would change the method by which the ads are stored/retrieved such as a mysql db.
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #8 (permalink)  
Old 05-05-08, 01:32 AM
DieuxSoldat_04 DieuxSoldat_04 is offline
Newbie Coder
 
Join Date: May 2008
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Hey,

Thanks for the code! I haven't tried it yet but I am about to. Just to be sure, is the following code layout how I could do it?

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<div class="sidecolumn">
<?php
session_start();
$_SESSION["counter"]=!empty($_SESSION["counter"])?$_SESSION["counter"]:0;
$_SESSION["counter"]++;
switch($_SESSION["counter"])
{
 case 1:
?>
  <div>
   Place first add here
  </div>
  <?php
  break;
 case 2:
 ?>
  <div>
   Place second add here
  </div>
  <?php
  break;
 case 3:
 ?>
  <div>
   Place third add here
  </div>
  <?php
  break;
 default:
 ?>
  <div>
  Place last add here
  </div>
  <?php
  $_SESSION["counter"]=0;
 }
?>
</div>
</body>
</html>
Once I find out where exactly it is suppose to go, I will give it a shot : D Also just to be sure, I replace every "ad here" with a script like this one:

Code:
<script type="text/javascript"><!--
google_ad_client = "pub-8412003942395982";
/* 468x60, created 4/23/08 */
google_ad_slot = "6187880626";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//-->
</script>
correct? : ]

Thanks once again for the immediate help!
Warm Regards,
Jason H.
Reply With Quote
  #9 (permalink)  
Old 05-05-08, 03:22 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
session_start will need to be put at the very start of the document before anything else, or you will get headers sent errors
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #10 (permalink)  
Old 05-05-08, 07:17 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
I put in the first two adds for you.
You put in the other five adds into the other five div's where I have the text place holders.

PHP Code:

<?php
session_start
();
$_SESSION["counter"]=!empty($_SESSION["counter"])?$_SESSION["counter"]:0;
$_SESSION["counter"]++;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<div class="sidecolumn">
<?php
switch($_SESSION["counter"])
{
 case 
1:
?>
  <div>
   <script type="text/javascript"><!--
   google_ad_client = "pub-8412003942395982";
   /* 468x60, created 4/23/08 */
   google_ad_slot = "6187880626";
   google_ad_width = 468;
   google_ad_height = 60;
   google_cpa_choice = ""; // on file
   //-->
   </script>
  </div>
  <?php
  
break;
 case 
2:
 
?>
  <div>
   <script type="text/javascript">
   AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0','width','160','height','600','src','http://www.Counter-Strike.com/affiliate/banners/cs-flash_160x600?actionURL=http://www.Counter-Strike.com/affiliate/idevaffiliate.php?id=2477_5_1_19','quality','high','pluginspage','http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash','movie','http://www.Counter-Strike.com/affiliate/banners/cs-flash_160x600?actionURL=http://www.Counter-Strike.com/affiliate/idevaffiliate.php?id=2477_5_1_19' ); //end AC code
   </script>
  </div>
  <?php
  
break;
 case 
3:
 
?>
  <div>
   Place third add here
  </div>
  <?php
  
break;
 case 
4:
 
?>
  <div>
   Place fourth add here
  </div>
  <?php
  
break;
 case 
5:
 
?>
  <div>
   Place fifth add here
  </div>
  <?php
  
break;
 case 
6:
 
?>
  <div>
   Place sixth add here
  </div>
  <?php
  
break;
 default:
 
?>
  <div>
   Place seventh add here
  </div>
  <?php
  $_SESSION
["counter"]=0;
 }
?>
I thought I made the quite clear in the previous post. Or didn't you read all of it?
__________________
Jerry Broughton

Last edited by job0107; 05-05-08 at 07:21 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Open Source Advertising php_scripts The Lounge 5 02-25-08 04:05 AM
New!! iAds 1.10 - Automated Forced Ads Script ihostdev General Advertisements 1 11-30-07 03:17 AM
Yahoo Ads Grabber The Lounge 7 05-31-06 01:05 PM
Classifieds ads script wanted. yacht Script Requests 2 11-14-05 01:43 AM
Complete Forum - Free phpBB & Invision hosting (textlink ads!) pcpp General Advertisements 0 11-13-04 10:31 PM


All times are GMT -5. The time now is 07:43 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.