Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    May 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Banner Rotation code

    Code:
    $random_number = rand(1, 5);
    
    $random_banner[1] = '<a href="http://www.blawgspot.com/"><img src="http://www.blawgspot.com/banner.gif" border="0" alt="BlawgSpot" style="float: right; padding: 7px;" /></a>';
    
    $random_banner[2] = '<a href="http://forumpostie.easywebbers.com"><img src="http://forumpostie.easywebbers.com/ads/banner.gif" border="0" alt="ForumPostie" style="float: right; padding: 7px;" /></a>';
    
    $random_banner[3] = '<a href="http://www.teenelement.com"><img src="http://images.teenelement.net/te_banner_FINAL.gif" border="0" alt="TeenElement" style="float: right; padding: 7px;" /></a>';
    I currently using this code for my forum's banner rotation script. I have three questions for this code:

    Question 1: I can have unlimited banners to be rotated right? The first line of code that has rand(1, 5); If I want more than 5 I just change that number?

    Question 2: How can I set it to have a banner everytime? What I mean is, on my forum sometimes when I refresh it, it doesn't have a banner showing. Sometimes I would have to refresh it 3 times to have it show a random banner. I want a banner to be shown always, but of course have it rotated.

    Question 3: How can I make the link be opened in a new window?

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    1. Yes you can, just change the number.
    2. Its because $rand_number is returning a number between 1 and 5 inclusively. Since you only have 3 banners it might return 4 or 5 and since you have no 4th or 5th images nothing shows up.
    3. If you aren't using a strict doctype you can use target="_blank".
    Finally all of these questions are 'Read the manual' type questions meaning learn to do a little more research on your own before asking simple questions.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    May 2007
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As Aerospace said.. use this code instead.. it should work

    Code:
    $random_number = rand(1, count($random_banner));
    
    $random_banner[1] = '<a href="http://www.blawgspot.com/"><img src="http://www.blawgspot.com/banner.gif" border="0" alt="BlawgSpot" style="float: right; padding: 7px;" /></a>';
    
    $random_banner[2] = '<a href="http://forumpostie.easywebbers.com"><img src="http://forumpostie.easywebbers.com/ads/banner.gif" border="0" alt="ForumPostie" style="float: right; padding: 7px;" /></a>';
    
    $random_banner[3] = '<a href="http://www.teenelement.com"><img src="http://images.teenelement.net/te_banner_FINAL.gif" border="0" alt="TeenElement" style="float: right; padding: 7px;" /></a>';
    Last edited by smalldog; 05-15-2007 at 10:17 AM.
    Forum for webmasters and developers
    http://www.htmlfrenzy.com
    Are you an IT expert? Join our Reward system
    www.htmlfrenzy.com/reward-system.php

  • #4
    New Coder
    Join Date
    May 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thx, but the code u gave me above doesn't random. It is ok, I got my own to work.

    I was wondering if I can ask another question: How can I use the code below as a banner to be rotated?

    Code:
    <script type="text/javascript"><!--
    auctionads_ad_client = "f6f7ea23731e71604b99";
    auctionads_ad_campaign = "";
    auctionads_ad_width = "468";
    auctionads_ad_height = "60";
    auctionads_ad_kw =  "Test";
    auctionads_color_border =  "CFF8A3";
    auctionads_color_bg =  "FFFFFF";
    auctionads_color_heading =  "00A0E2";
    auctionads_color_text =  "000000";
    auctionads_color_link =  "008000";
    --></script>
    <script type="text/javascript" src="http://ads.auctionads.com/pagead/show_ads.js">
    </script>

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Quote Originally Posted by ostudioo View Post
    Thx, but the code u gave me above doesn't random. It is ok, I got my own to work.

    I was wondering if I can ask another question: How can I use the code below as a banner to be rotated?
    The same way you got the others to rotate. Its only html. Smalldog's code would have worked if he put $random_number after the $random_banner array. The array isn't created yet so it doesn't know the count of the array.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    New Coder
    Join Date
    May 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So just add $random_banner[4] = before the auctionad code?

  • #7
    Regular Coder
    Join Date
    May 2007
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry that was my bad right code is this:

    Code:
    $random_banner[1] = '<a href="http://www.blawgspot.com/"><img src="http://www.blawgspot.com/banner.gif" border="0" alt="BlawgSpot" style="float: right; padding: 7px;" /></a>';
    
    $random_banner[2] = '<a href="http://forumpostie.easywebbers.com"><img src="http://forumpostie.easywebbers.com/ads/banner.gif" border="0" alt="ForumPostie" style="float: right; padding: 7px;" /></a>';
    
    $random_banner[3] = '<a href="http://www.teenelement.com"><img src="http://images.teenelement.net/te_banner_FINAL.gif" border="0" alt="TeenElement" style="float: right; padding: 7px;" /></a>';
    
    $random_number = rand(1, count($random_banner));
    Forum for webmasters and developers
    http://www.htmlfrenzy.com
    Are you an IT expert? Join our Reward system
    www.htmlfrenzy.com/reward-system.php


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •