views:

161

answers:

2

I have table with advertisement in MySQL. I would like to rotate banners by order (NOT RANDOM). What function or mechanism I need to SELECT advertisement from MySQL table to show it in order, like 1, then 2, then 3 ... then again 1,2,3... ?

+1  A: 

Show banner 1, then banner 2, then banner 3 to the same user on different page loads?

You could use a cookie:

//the banner that the user last saw
$banner = (isset($_COOKIE['banner']) && $_COOKIE['banner'] < 3)? $_COOKIE['banner']++ : 1;

//mysql to select and show the banner

$_COOKIE['banner'] = $banner;
SeanJA
A: 

If you want each hit to get the next banner (in order), then you need to create a place on your server to store what the current banner number is. A table in MySQL would be the obvious choice. Then get increment the counter in the table every hit and reset it to the start when you get to the last banner.

Eli