Hello!
I have some banners at DB. Every banners has params:
position
id
showes
showed
I try to make system, that will shows banners for current user not more that 2 times.
For example, i entered to site, and i see at top position 1 banner, at right side 1 banner and at left 1 banner.
When i make reload page i will do:
1) Will check if common number of banner from position 1 is larger that 0 and parametr showed > 0, then to reduce "showed" parametr for banner on 1 minus (will be 2).
And this operation must do for each banners. If "showed" == 0 need show any banner from position and check it same (item
1)
Now i have a bad code, may by you could help me make it thoroughly
<?
function GetBanners($options = array('showes > '=>'0')){
$showes = 3;
$settings = array(
1 => array('height' => 90, 'width' => 1149),
2 => array('height' => 50, 'width' => 408),
3 => array('height' => 234,'width'=> 304),
4 => array('height' => 50, 'width' => 408),
5 => array('height' => 50, 'width' => 560)
);
$banners_new = array();
$new_banners = array();
$ci=&get_instance();
$banners = $ci->banners_model->GetBanners($options);
if (!empty($banners)) {
foreach ($banners as $key => $value) {
$banners_new[$value->position][$value->id]['status'] = $value->status;
$banners_new[$value->position][$value->id]['showes'] = $value->showes;
$showes_array[$value->id] = $showes;
if ($value->type == 0) {
$banners_new[$value->position][$value->id]['code'] = (empty($value->code))? '<a title="'.$value->name.'" target="_blank" href="'.$value->link.'"><img width="'.$settings[$value->position]["width"].'" height="'.$settings[$value->position]["height"].'" src="'.base_url().$value->image.'"/></a>' : $value->code;
$banners_new[$value->position][$value->id]['type'] = 0;
} else {
$banners_new[$value->position][$value->id]['type'] = 1;
$banners_new[$value->position][$value->id]['code'] = '
<object height="'.$settings[$value->position]["width"].'" width="'.$settings[$value->position]["height"].'">
<param name="movie" value ="'.$value->image.'"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#ffffff"></param>
<param name="flashwars" value=""></param>
<embed type="application/x-shockwave-flash" height="'.$settings[$value->position]["height"].'" width="'.$settings[$value->position]["width"].'" src="'.$value->image.'" quality="high" bgcolor="#ffffff" wmode="window" menu="false" flashwars="">
</embde>
</object>';
}
}
}
if (!isset($_SESSION['showed_banners']) && empty($_SESSION['showed_banners'])){ $_SESSION['showed_banners'] = $showes_array;}
$temp = $_SESSION['showed_banners'];
foreach ($banners_new as $key => $value) {
foreach ($value as $keys => $val){
if (array_key_exists($keys, $temp) && $_SESSION['showed_banners'][$keys] >0) {
$_SESSION['showed_banners'][$keys] = $temp[$keys]-1;
switch ($key) {
case '1':
$new_banners[$key][] = $val['code'];
break;
case '2':
# code...
break;
case '3':
$new_banners[$key] = $val['code'];
break;
case '4':
# code...
break;
default:
# code...
break;
}
} else {
$ci->banners_model->Update(array('showes' => $val['showes'] - $showes), $keys);
}
}
}
if (empty($new_banners)) {
unset($_SESSION['showed_banners']);
GetBanners();
}
return $new_banners;
}
?>