Simple basic randomizer.

Discussion in 'PHP' started by Robert Allen, May 5, 2007.

  1. #1
    Hi,

    I have 3 images, fish-cartoon.png, fish-cartoon2.png and fish-cartoon3.png.

    All 3 of the images are at images/.

    They are all the same pixel size, and similar kb size, and i want them to randomize.

    How could i do this using PHP?

    It is for fitfishes.com

    ROb
     
    Robert Allen, May 5, 2007 IP
  2. phd

    phd Active Member

    Messages:
    496
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    60
    #2
    rename first image i.e. fish-cartoon.png to fish-cartoon1.png

    use the function rand(1,3) http://www.php.net/rand

    and you've done it..
     
    phd, May 5, 2007 IP
    Robert Allen likes this.
  3. Robert Allen

    Robert Allen Peon

    Messages:
    2,685
    Likes Received:
    247
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The problem is that i know no PHP code whatsoever, and i am unsure what to write, would this be correct?

    
    <?php
    echo rand() . "fish-cartoon.png";
    echo rand() . "fish-cartoon2.png";
    echo rand() . "fish-cartoon3.png";
    ?>
    
    Code (markup):
    Rob
     
    Robert Allen, May 5, 2007 IP
  4. kaisellgren

    kaisellgren Well-Known Member

    Messages:
    472
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    #4
    <?php
    
    $list = array('a.jpg','b.jpg','c.jpg');
    shuffle($list);
    echo '<img src="images/'.$list[0].'" />';
    
    ?>
    PHP:
     
    kaisellgren, May 5, 2007 IP
    Robert Allen likes this.
  5. Robert Allen

    Robert Allen Peon

    Messages:
    2,685
    Likes Received:
    247
    Best Answers:
    0
    Trophy Points:
    0
    #5
    THANK YOU.

    Your amazing, thanks for the information.

    Rob
     
    Robert Allen, May 5, 2007 IP
  6. kaisellgren

    kaisellgren Well-Known Member

    Messages:
    472
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    #6
    no problem. just press the reputation button :p
     
    kaisellgren, May 5, 2007 IP
  7. Robert Allen

    Robert Allen Peon

    Messages:
    2,685
    Likes Received:
    247
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I already did...Enjoy!

    Rob
     
    Robert Allen, May 5, 2007 IP