Jump to content

Ad banners, set to random


dachshund

Recommended Posts

Hi, at the moment on my site I have four ad banners, all the same size. At the moment they are in separate areas of the site and stay as they are.

 

Now I would like to have them all in the same position, but on rotation/random. So the banner changes between all four each time you refresh/visit the page.

 

I know how to do this for the image with rand() but not for the image and the accompanying like <a href="">

 

Anyone know how I can do this?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/186506-ad-banners-set-to-random/
Share on other sites

This would suit you nicely (UNTESTED):

 

<?php

$ads = array(
    array("http://www.google.com/", "/images/googlead.jpg"), 
    array("http://www.yahoo.co.uk/", "/images/yahooad.jpg")
);

$i = rand(0, (count($ads)-1));
echo "<a href=\"".$ads[$i][0]."\"><img src=\"".$ads[$i][1]."\" /></a>";

?>

 

You can then put that in a separate file and include it in a page.

 

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.