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> Link to comment https://forums.phpfreaks.com/topic/60754-solved-random-image-with-link/ 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? Link to comment https://forums.phpfreaks.com/topic/60754-solved-random-image-with-link/#findComment-302233 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 Link to comment https://forums.phpfreaks.com/topic/60754-solved-random-image-with-link/#findComment-302263 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 Link to comment https://forums.phpfreaks.com/topic/60754-solved-random-image-with-link/#findComment-302354 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? Link to comment https://forums.phpfreaks.com/topic/60754-solved-random-image-with-link/#findComment-302402 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.