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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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... Quote Link to comment 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 Quote Link to comment 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.... Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.