Jump to content

[SOLVED] random image with link


alapimba

Recommended Posts

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

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 ;)

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?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.