问题描述
就像随机图像生成器一样(例如: http://www. (仅按顺序排列).我正在运行横幅广告,客户希望它们在每次页面加载时依次运行1、2、3、4、5.所以他们只是轮流走.加载5页,然后重新开始循环.
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!
推荐答案
<?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];
当然,您需要实际的HTML代码,而不是Ad1
,Ad2
等.
Of course you'd need the actual HTML code instead of Ad1
, Ad2
, etc.
如果您不希望注意到,可以在session_start()
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;
这篇关于按顺序打印数组的每个项目-每页刷新一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!