alapimba Posted July 19, 2007 Share Posted July 19, 2007 Hello, can anyone give me some help on a script to random display images with links? i want to randomise this 3 images that have diferent links:<a href="produtos_alimentares.php?anchor=seleccao"><img src="images/tecnologia.jpg" width="208" height="139" border="0" align="right" /></a> <a href="produtos_alimentares.php?anchor=carga"><img src="images/tecnologia1.jpg" width="208" height="139" border="0" align="right" /></a> <a href="produtos_alimentares.php?anchor=outra"><img src="images/tecnologia2.jpg" width="208" height="139" border="0" align="right" /></a> Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted July 19, 2007 Share Posted July 19, 2007 wait... you want them all to appear on the page in a random order... or you want one to display? Quote Link to comment Share on other sites More sharing options...
chigley Posted July 19, 2007 Share Posted July 19, 2007 To display one randomly selected one: <?php $options = array("<a href=\"produtos_alimentares.php?anchor=seleccao\"><img src=\"images/tecnologia.jpg\" width=\"208\" height=\"139\" border=\"0\" align=\"right\" /></a>", "<a href=\"produtos_alimentares.php?anchor=carga\"><img src=\"images/tecnologia1.jpg\" width=\"208\" height=\"139\" border=\"0\" align=\"right\" /></a>", "<a href=\"produtos_alimentares.php?anchor=outra\"><img src=\"images/tecnologia2.jpg\" width=\"208\" height=\"139\" border=\"0\" align=\"right\" /></a>"); shuffle($options); echo $options[0]; ?> To display all of them in a random order: <?php $options = array("<a href=\"produtos_alimentares.php?anchor=seleccao\"><img src=\"images/tecnologia.jpg\" width=\"208\" height=\"139\" border=\"0\" align=\"right\" /></a>", "<a href=\"produtos_alimentares.php?anchor=carga\"><img src=\"images/tecnologia1.jpg\" width=\"208\" height=\"139\" border=\"0\" align=\"right\" /></a>", "<a href=\"produtos_alimentares.php?anchor=outra\"><img src=\"images/tecnologia2.jpg\" width=\"208\" height=\"139\" border=\"0\" align=\"right\" /></a>"); shuffle($options); foreach($options as $option) { echo "{$option}<br />\n"; } ?> Hope that helped Quote Link to comment Share on other sites More sharing options...
alapimba Posted July 19, 2007 Author Share Posted July 19, 2007 it was to display one of them randomly. thanks for your help Quote Link to comment Share on other sites More sharing options...
bronzemonkey Posted July 19, 2007 Share Posted July 19, 2007 Just want to thank chigley for this. I needed the same thing but for blocks of text. It also got me thinking about a variation on this concept: I've got 5 different "section navigations" for my website. In the "shoes section" a navigation with links to "men's shoes", "women's shoes", "kid's shoes" is displayed...this navigation is also shoes when you're on the "men's shoes" page etc. The same thing goes on for each section in the site. At the moment I just have all 5 different "section navigations" saved as php files and use require to insert the relevant navigation. How would I go about putting all 5 navigations into a single php file required by every page, but only displaying the single relevant navigation for the section the page is part of? 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.