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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.