Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Junior Member
    Join Date
    Oct 2003
    Posts
    4
    Member #
    3659
    I want to script my site so that a different ad loads each time the page loads.

    for example:
    I want it so there is a 20% chance that ad1 will load on the page when it is opened.
    I want it so there is another 20% chance that ad2 will load on the page instead.
    I want it so there is a 20% chance that ad3 will load on the page instead of the previous two, and so on and so forth.

    so how can I script this?

    thanks in advance

  2.  

  3. #2
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    How many adverts are there? So basically what you want is all of the adverts to have an equal chance?
    JR

  4. #3
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    Try something like this:

    PHP Code:
    <html>
    <head>
    </head>

    <body>
    <?php
    $advert 
    = array (
    "image1.gif",
    "image2.gif",
    "image3.gif",
    "image4.gif",
    "image5.gif"
    );
    $i rand(0sizeof($advert) - 1);
    echo 
    "<img src=".$advert[$i].">";
    ?>
    </body>
    </html>
    Make sure you save the page as .php
    JR

  5. #4
    Junior Member
    Join Date
    Oct 2003
    Posts
    4
    Member #
    3659
    thank you

    and all i have to replace is the image.gifs?

  6. #5
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    don't use sizeof()... instead, use $array_name.length() where you can for compatibility.

  7. #6
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    Compatibility? PHP is server side so it depends on the server doesn't it?
    JR


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:47 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com