Jump to content
Sign in to follow this  
Xtazy

switch banners

Recommended Posts

ok, so I have two banners for my website (till now), and I want them to be changed everytime the guest moves from one page to another one...even though he is in index.html, when he refreshes the page i want the banner changed...i think i should have posted this on the javascript category, dunno...thanx in advance!xtazy

Share this post


Link to post
Share on other sites

All you need is a random number generator, like this one:http://www.php.net/manual/en/function.mt-rand.phpOnce you generate a random number you can do whatever you want with it. You can get a record from the database with the number as an ID, use it to refer to an element in an array, use it to refer to a numbered file, whatever you want to do.

Share this post


Link to post
Share on other sites

Ah well, I've finally found a good script. Take a look:

	  <?php	  $banner[1]['link'] = "http://something.com";	  $banner[1]['img'] = "picture.jpg";   	  $banner[2]['link'] = "http://something.com";  	  $banner[2]['img'] = "picture.jpg";   	      	  $banner[3]['link'] = "http://something.com";	  $banner[3]['img'] = "picture.jpg";	  $banners=3; 	  srand((double)microtime()*1000000); 	  $random = rand(1,$banners);	  echo "<a href=\"".$banner[$random]['link']."\"><img src=\"".$banner[$random]['img']."\" border=\"0\"></a>";  	  ?>

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...