Forum Moderators: coopster

Message Too Old, No Replies

Quick script for rotating photos?

         

kenfused

5:10 am on May 19, 2008 (gmt 0)

10+ Year Member



Hi, was hoping someone could help me out...
this seems simple but I can't seem to get it to work.

I have 4 photos a.jpg, b.jpg, c.jpg and d.jpg

How do I have a php script put a photo/link on my index page, but then rotate (or randomly pick) one photo?

I think it should be easy, but I can't seem to get mine working!

tomda

10:22 am on May 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you want them to rotate every time the page is reloaded (reshuffle) or do you want to rotate within the page (like a slideshow).

Tomda

dublinmike

10:43 am on May 19, 2008 (gmt 0)

10+ Year Member



Try...


<?php
// ASCII characters of a-d...
$photo_range = array(97,100);
?>
<img src="<?=chr(rand($photo_range[0],$photo_range[1]));?>.jpg">

dreamcatcher

11:27 am on May 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or why not just range:

$pics = range('a','d');
shuffle($pics);
echo $pics[0].'.jpg';

dc

jatar_k

11:48 am on May 19, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



in the future for random things I would use numbers for the pic names instead of strings