Since it is a Saturday and I only spent a few hours at work today, I didn’t have a chance to do anything too fun or innovative which means I don’t have anything new to write about. So instead I thought I would write a quick helpful tutorial on how to create randomly rotating images on refresh using some simple PHP.
The basic theory is to name each image using a number. For example: image1.jpg, image2.jpg, and so on. Each image should have a number in a consistent location in an ongoing series without skipping a number. Once you have all your images, you can randomly display them using some very simple PHP.
Below is an example:
<?PHP //USE PHP RAND FUNCTION TO CREATE A RANDOM NUMBER $number = rand(1,7); //DISPLAY A RANDOM IMAGE IN RANGE image1.jpg - image7.jpg $output = "<img src=\"image{$number}.jpg\" alt=\"Image\" title=\"Image\" />"; //OUTPUT THE IMAGE TO THE BROWSER echo($output); ?> |
Soon I will show a more detailed example that shows how to switch images without consistent names.
Leave A Comment