1. Home
  2. Computing & Technology
  3. PHP / MySQL
photo of Angela Bradley
Angela's PHP / MySQL Blog

By Angela Bradley, About.com Guide to PHP / MySQL

Random Banner Rotation

Thursday April 13, 2006
Showing a random image or random banner advertisement on your website is much easier than you might think. We first assign each banner a number and then generate a random number using rand (). We then display the banner that corresponds to the number generated by rand (). You can store more than just the banner, but also link URL, alt tags, or any other information you may want, as long as you keep it assigned to the same number.
Comments
April 13, 2006 at 1:17 pm
(1) James says:

I didn’t realise it was this easy. I assume the same principle applies to random quotes?

April 14, 2006 at 8:57 pm
(2) Stephen Chapman says:

You can handle any random content the same way.

The big advantage of doing the random selection server side before delivering the page rather than client side in Javascript (as many people do) is that the server side solution always works, the Javascript solution relies on Javascript being enabled in the browser.

February 19, 2009 at 4:15 am
(3) Stuart says:

the link to download the full script appears to be broken (frustrating because this is exactly what I am trying to do at the moment :-) )

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL

©2009 About.com, a part of The New York Times Company.

All rights reserved.