开发者

Php + MySQL banner rotator by order

开发者 https://www.devze.com 2022-12-28 04:24 出处:网络
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 i

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

精彩评论

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

关注公众号