#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Cleveland
    Posts
    16
    Rep Power
    0
    Hello. I am trying to develop a banner ad rotator on my site. I DO NOT need to know the precise number of ads served per banner.
    Therefore, I do not want phpAds as it would be overkill and slow down my site.

    I have 3 banner spaces per page. Currently, I have 4 different sponsors. I just wanted to run a random number mechanism so that every tme the page is requested, 3 out of the available 4 banners are chosen automatically. So my current doe (pusedo) is something like this:

    seed...
    rand...
    if($x=1){
    banner1
    banner2
    banner3
    }
    if($x=2){
    banner2
    banner3
    banner4
    }
    if($x=3){
    banner3
    banner4
    banner1
    }
    if($x=4){
    banner4
    banner1
    banner2
    }

    Is this the best way? I do not see his method as being very scalable as it requires me to manually input the possible combinations. I only need a simple solution that is scalable to many sponsors but since I do NOT need to know exact impression levels (all sponsors divide up the impressions equally), I do not want to use MYSQL to "kill a fly with hammer."

    Thank you
  2. #2
  3. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    61
    I don't have the time to actually solve your problem, but it goes something like this:

    1. Create an array of n objects (n being the number of banners. At first you can just enter an the number manually. When you learn a little more about PHP's file and directory functions, you can get PHP to simply read the number of banner graphics in your banners directory.)

    2. For x = 0 to n call banner[n] (See PHP's documentation on for loops)

    3. Then randomize the output of banner[n]
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Cleveland
    Posts
    16
    Rep Power
    0
    Thanks for your reply. So to my understanding, you are suggestion the following:
    array(...) // n objects
    for(i=0;i<n;i++){
    print(banner[i])
    }

    where would the random go? Inside the for loop? But would this allow two banners from the same sponsor to be chosen in the same loop? The key is that once a banner is chosen, it must be not chosen again in the loop. Also, in this case, there are n=4 sponsor banners, but I only want to display 3 banners at a time. With the for loop, would not this display 4 banners after a run?

    Thanks

    tennisguy
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    3
    Rep Power
    0
    Here's some code I use for a Pwd generator :

    $charset="0987654321";
    $pwd=$charset[rand(0,8)+1]

    that basically lifts a digit from the srting which then gets done 8 times to make an 8-=digit PW...

    if you number the banners ban000 ban001 ban002 etc etc .. you can use a similar string-based idea and then do:

    $banname="ban".$randomnumberstring
    print "<img src="$banname">";

    which would put the appropriate numbered banner in there



    ------------------


    GE @ Obsidian Software

Similar Threads

  1. MYSQL, php, random generate
    By LeBoOo in forum PHP Development
    Replies: 2
    Last Post: September 30th, 2004, 01:47 PM
  2. generating random numbers of a fixed length
    By alexh in forum PHP Development
    Replies: 3
    Last Post: June 24th, 2004, 03:22 AM
  3. script for 9 random & unique numbers 1 - 30
    By thall89553 in forum ASP Programming
    Replies: 1
    Last Post: February 12th, 2004, 04:01 PM
  4. Writing array of random numbers to a database
    By Beda in forum ASP Programming
    Replies: 2
    Last Post: February 2nd, 2004, 03:34 PM
  5. Random numbers
    By Sixfinger in forum C Programming
    Replies: 4
    Last Post: February 2nd, 2004, 04:11 AM

IMN logo majestic logo threadwatch logo seochat tools logo