www.webdeveloper.com
Results 1 to 3 of 3

Thread: Random Ad Picker

  1. #1
    Join Date
    Aug 2008
    Posts
    2

    Random Ad Picker

    This is supposed to randomly generate a number which will then select an ad image, its link, and text to display. I cant get it to work. Any suggestions?

    PHP Code:
    <?php
    //---- Ad rotator
    ?>

    <p><a href="http://<?php print $link?>"><img src="<?php print $ad?>" alt="<?php print $alt?>" width="150" height="230" border="0"> </a> &nbsp;</p>

    <?php

    //random number generator
    $ad_number rand(1,2);

        
    //assign link & ad based in random number
        
    if ($ad_number == "1"
            {
                
    $link "www.awebsite.com";
                
    $ad "/ads/ja-curren-ad.gif";
                
    $alt "Ad Number One";
            }
        elseif (
    $ad_number == "2"
            {
                
    $link "www.website.com";
                
    $ad "/ads/place-ad.gif";
                
    $alt "Ad Number Two";
            }
        else 
            {
                
    $link "www.another-website.com";
                
    $ad "/ads/place-ad.gif";
                
    $alt "Place an ad!";
            }



    //---- END OF RANDOM AD GENERATOR 
    ?>

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    your code is out of order - you need to set the variable values before you try to print them out.

  3. #3
    Join Date
    Aug 2008
    Posts
    2

    Thanks!

    Wow i cant believe i didnt notice i did that. But i am kinda new to PHP.
    Thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles