横幅系统,巧妙展示 [英] Banners system, clever showing

查看:94
本文介绍了横幅系统,巧妙展示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!

我在DB上有一些横幅。每个横幅都有参数:



Hello!
I have some banners at DB. Every banners has params:

position //1 - top banners, 2 - right banners, 3 - left banners
id
showes //2000 Common number of showing banners
showed //A number of showing banner for current user, default = 3





我尝试制作系统,这将显示横幅对于当前用户不超过2次。



例如,我进入网站,我看到顶部位置1横幅,右侧1横幅和左侧1横幅。



当我重新加载页面时,我会这样做:



1)将检查位置1的公共横幅数是否大于0且参数显示> 0,然后在1减去(将为2)减少横幅的显示参数。



此操作必须为每个横幅做。如果显示== 0需要从位置显示任何横幅并检查相同(项目 1



现在我的代码不好,可以由你帮助我彻底完成它





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) {
               //$key - position

          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;

}
?>

推荐答案

options = array(' showes>' => ' 0')){

options = array('showes > '=>'0')){


showes = 3 ;
showes = 3;


settings = array(

1 =>数组(' height' => 90,' width' => 1149),
2 =>数组(' height' => 50,' width' => 408),
3 =>数组(' height' => 234,' width' => 304),
4 =>数组(' height' => 50,' width' => 408),
5 =>数组(' height' => 50,' width' => 560)
);

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) );


这篇关于横幅系统,巧妙展示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆