开发者

Php + MySQL banner rotator by order

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 My开发者_运维知识库SQL table to show it in order, like 1, then 2, then 3 ... then again 1,2,3... ?


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;


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜