Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 04-29-2007, 08:40 AM   #1 (permalink)
markster
Code Monkey
 
markster's Avatar
 
Join Date: Jun 2006
Posts: 65
markster is on a distinguished road
Banner Rotator

How would I go about creating a banner rotator through which i could controll the probablility of an ad appearing? I can create a script to display a random ad each time, but I'm not sure on creating a script with probability. I though the array of ads would look like this:

PHP Code:
# $banners = array("link","img",probability);
$banners = array("banner1.php","banner1.gif",0.5);
$banners = array("banner2.php","banner2.gif",0.25);
$banners = array("banner3.php","banner3.gif",0.25); 
In this example banner 1 would be shown half the time, and banner 2 and 3 a quarter of the time. I'm just not sure how the rest would work

Please help if you have a rough idea.
__________________
Stuff4Web.co.uk - The ultimate resource for webmasters

50% off all orders £1-£50! Just enter the code AGSIG01 at the checkout! Offer ends: 01/09/2008
markster is offline   Reply With Quote
Old 04-29-2007, 11:11 AM   #2 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 598
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
You could do something like this:
PHP Code:
$randVal rand(1,100)/100;
$done 0;
$counter 0;
while(!
$done){
    
$prob $banners[$counter][2];
    if(
$prob $randVal){
        
$done 1;
    }
    else {
       
$counter++;
       
$randVal $randVal $prob;
    }
}
someFunctionToDisplay($banners[$counter]); 
*Note: I typed this straight into the text box and my php is a little rusty so this code probably needs some love, but it should demonstrate the basic idea.
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Reply

Bookmarks

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 10:20 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting