destoon 增删改查

switch($action) {
    case 'add':
    //添加页面
        if($submit) {
            // 不允许重名,直接添加时
            $old = $db->get_one("SELECT itemid FROM {$DT_PRE}brandmap WHERE name = '".trim($post['name'])."'");
            if ($old) msg('当前省份信息已经存在,不允许重复添加,只允许编辑');
            $arr['name']=empty($post['name'])?'':trim($post['name']);
            $arr['pinyin']=empty($post['pinyin'])?'':$post['pinyin'];
            $arr['num']=$post['num'];
            $arr['bangdannum']=$post['bangdannum'];
            $arr['catnum']=$post['catnum'];
            $arr['title']=$post['title'];
            $arr['url']=$post['url'];
            $arr['zhizhubrand']=$post['zhizhubrand'];
            $arr['addtime']=$DT_TIME;
            foreach ($arr as $key => $val)
             {
                $k[]=$key;
                $v[]=$val;
            }
            $vs ="'" . implode("','", $v). "'";
            $ks=implode(',', $k);
            $res=$db->query("INSERT INTO `{$DT_PRE}brandmap` ($ks) VALUES ($vs)");
            if($res){
                dmsg('添加成功','?moduleid='.$moduleid);
            }else{
                msg($do->errmsg);
            }
        } else {
            include tpl('edit', $module);
        }
    break;
    case 'edit':
    //修改页面
        if(!empty($itemid))
        {    
            $item=$db->get_one("SELECT * FROM {$DT_PRE}brandmap WHERE itemid='$itemid'");    
            $item['addtime']=empty($item['addtime'])?'':timetodate($item['addtime'],5);
            if(!empty($submit))
            {    
                if($item['name']==$post['name']&&$item['pinyin']==$post['pinyin']&&$item['num']==$post['num']&&
                    $item['bangdannum']==$post['bangdannum']&&$item['catnum']==$post['catnum']&&$item['title']==$post['title']&&
                    $item['url']==$post['url']&&$item['zhizhubrand']==$post['zhizhubrand']){
                    msg('没有修改');
                }
                $arr['name']=empty($post['name'])?'':trim($post['name']);
                $arr['pinyin']=empty($post['pinyin'])?'':$post['pinyin'];
                $arr['num']=$post['num'];
                $arr['bangdannum']=$post['bangdannum'];
                $arr['catnum']=$post['catnum'];
                $arr['title']=$post['title'];
                $arr['url']=$post['url'];
                $arr['zhizhubrand']=$post['zhizhubrand'];
                $arr['addtime']=$DT_TIME;
                foreach ($arr as $k => $v)
                 {    
                     $db->query("UPDATE `{$DT_PRE}brandmap` SET `$k`='$v' WHERE `itemid`=$itemid");
                    
                }
                dmsg('修改成功','?moduleid='.$moduleid);
            }
            include tpl('edit',$module);
        }    
    break;
    case 'delete':
    //删除页面
        if(!empty($itemid))
        {
            if (is_array($itemid) ) 
            {
                $id=implode(',', $itemid);
            }else{
                $id=$itemid;
            }
            $res=$db->query("DELETE FROM `{$DT_PRE}brandmap` WHERE `itemid` in ($id)");
            if($res){
                dmsg('删除成功','?moduleid='.$moduleid);
            }else{
                dmsg($do->errmsg);
            }
        }
    break;
    default:
    //展示页面
        if($page > 1 && $sum) {
            $items = $sum;
        } else {
            $r = $db->get_one("SELECT COUNT(*) AS num FROM {$DT_PRE}brandmap  WHERE $condition");
            $items = $r['num'];
        }
        $pages = pages($items, $page, $pagesize);
        $result = $db->query("SELECT * FROM {$DT_PRE}brandmap WHERE $condition order by $order  LIMIT $offset,$pagesize");
        while($r = $db->fetch_array($result)) 
        {    $r['map']=DT_SKIN.'brandmap/brand_'.$r['pinyin'].'1.png';
                $r['map2']=DT_SKIN.'brandmap/brand_'.$r['pinyin'].'2.png';
            $r['addtime'] = timetodate($r['addtime'], 5);
            $lists[] = $r;
        } 
        $menuid = 1; 
        include tpl('index', $module);
    break;
}

猜你喜欢

转载自www.cnblogs.com/yx520zhao/p/11645742.html
今日推荐