views:

24

answers:

1

Like a random image generator (ex: http://www.dustindiaz.com/a-simple-php-image-rotator/), only in a sequential order. Im running banner ads, and the client would like them run 1,2,3,4,5 in order per page load. So they just go round robin. 5 page loads, then the cycle start again.

Any ideas? I've googled for a while, and i'm not finding anything.

any help would be great, thanks much!

A: 
<?php

// start session
session_start();
$ads = array ('Ad1', 'Ad2', 'Ad3', 'Ad4', 'Ad5');

// rotate
$id = ++$_SESSION['ad_id'] % count($ads);
$_SESSION['ad_id'] = $id;

// display ad
echo $ads[$id];

Of course you'd need the actual HTML code instead of Ad1, Ad2, etc.

If you don't want notices the following piece of code can be added after session_start()

if (!isset($_SESSION['ad_id'])) $_SESSION['ad_id'] = 0;
quantumSoup
Works great, but gives this warning just above: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent
realcheesypizza
o never mind, i suppressed them: error_reporting(0); thanks alot soup!!!
realcheesypizza
done, thanks !!
realcheesypizza