Do you wish to rotate a banner or image on every load of website ? Some simple PHP techniques and codes will help you. The changed image may or may not be of same size
Trick 1: No Database use needed.
In this trick we will number all images to be rotated sequentially. e.g. 1.jpg,2.jpg,3.jpg …10.jpg
On page load we will select random number from our range i.e. 1 to 10
So the image code will be
<img src=”images/<?php echo rand(1,10); ?>”.jpg>
Where images is your image folder.
Trick 2: Use of database.
This trick requires a MYSQL database. In this we will store image file name in a table named images. This method allows to use multiple extension images.
| id | image |
| 1 | abcd.jpg |
| 2 | efgh.jpg |
<?php
$sql=”select * from images where id order by rand()”;
$imagename=mysql_fetch_assoc(mysql_query($sql));
echo “<img src=’”images/”.$imagename['image'].”‘>”;
?>
Using any of above code will display new image on every page load. Other methods are also there, comment if you have better ideas.