phpSensei Posted September 3, 2007 Share Posted September 3, 2007 I want to know how to make a little script that changes an image displayed on a page... Lets we are on the home page, and there is an image of a cat... Refresh the page, and that image changes to a dog... and so on. Link to comment https://forums.phpfreaks.com/topic/67820-solved-change-image-on-refresh/ Share on other sites More sharing options...
AbydosGater Posted September 3, 2007 Share Posted September 3, 2007 Im going to take it that you want it to be random ... If you dont say .. Also you would have the chance of the same one coming up more then once but it can be maded to stop that.. $randomImages = array("dog", "cat"); $rand = array_rand($randomImages); echo "<img src='/images/$rand.gif'></img>"; Will randomly select dog or cat and display it.. If you dont want it random just make other code to change the $rand variable that declares what image to be displayed.. Andy Link to comment https://forums.phpfreaks.com/topic/67820-solved-change-image-on-refresh/#findComment-340856 Share on other sites More sharing options...
pocobueno1388 Posted September 3, 2007 Share Posted September 3, 2007 Do something like this: <?php $images = array("1.jpg", "2.jpg", "3.gif"); shuffle($images); echo "<img src='".$images[0]."'>"; ?> I was beat to it...but here is mine anyways. Link to comment https://forums.phpfreaks.com/topic/67820-solved-change-image-on-refresh/#findComment-340861 Share on other sites More sharing options...
phpSensei Posted September 3, 2007 Author Share Posted September 3, 2007 wow, thankyou thankyou both.... From now on, I will use this method to randomize things... Link to comment https://forums.phpfreaks.com/topic/67820-solved-change-image-on-refresh/#findComment-340863 Share on other sites More sharing options...
AbydosGater Posted September 3, 2007 Share Posted September 3, 2007 pocobueno1388: No matter who gets there first.. different methods of coding techniques..are always helpful. phpSensei.. No Prob! Glad to be of some help. Andy Link to comment https://forums.phpfreaks.com/topic/67820-solved-change-image-on-refresh/#findComment-340877 Share on other sites More sharing options...
phpSensei Posted September 3, 2007 Author Share Posted September 3, 2007 pocobueno1388: No matter who gets there first.. different methods of coding techniques..are always helpful. phpSensei.. No Prob! Glad to be of some help. Andy Ha, both methods are amazing... I needed this for an MMORPG, so when the user refreshes the page, his/her character will be in a different position.... Link to comment https://forums.phpfreaks.com/topic/67820-solved-change-image-on-refresh/#findComment-340883 Share on other sites More sharing options...
AbydosGater Posted September 4, 2007 Share Posted September 4, 2007 Yeah that should do exactly what you want then Andy Link to comment https://forums.phpfreaks.com/topic/67820-solved-change-image-on-refresh/#findComment-341142 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.