SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help w/ rotate item syntax

    yesterday, I posted a question into the general programming thrread. today, I actually have code to troubleshoot.

    I'm trying to cycle some html docs on pageload. I found a chunk of code that cycles images based on a time hash. code is
    Code:
    <?php  $i = (bcmod(intval(time()),60)) % 6;
    print '<img src="images/header_image' . $i . '.jpg" style="float:right;" />'
    ?>
    I'd like to modify that to pull html files into an iframe, but so far, I'm getting the syntax wrong (or I'm trying to use a screwdrive to hammer in a nail)

    Any advice?
    Code:
    <?php $i = (bcmod(intval(time()),60)) % 6;
    print '<iframe src="directory/filename' . $i . '.html" />'
    ?>

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If its one of 10 random file names you want you can do this;
    PHP Code:
    echo rand(1,10) . '.html' ;

    //e.g. 7.html 
    or if you have an array of real file names;
    PHP Code:
    $a = array('this.html''that.html');

    $key array_rand($a ) ;

    echo 
    $a[$key];

    //e.g. that.html 
    The second could be better because you could populate the array $a from the contents of a given folder. Drop a new file into the folder and it gets put into the array.

    Is this what you are after though, a totally random selection CAN appear twice in succession.


Bookmarks

Posting Permissions

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