一个码菜

导航

鑫安财富项目随记6--如何进行多项删除

这几天浑浑噩噩的,就没写博了,今天花了一早上搞了下多项删除功能,下面是一点心得

首先是页面的

<a href="javascript:void(0)" onclick="delModel({form:'expertListForm',msg:'确定要删除所选中的业务员吗?<br />删除的业务员无法找回!!'})"><button class="operating_btn" type="button"><span class="delete">批量删除</span></button></a>
<form name="expertListForm" action="{url:/member/expert_dell}" method="post" >


然后是php

function expert_dell(){
    //post数据
    $id = IFilter::act(IReq::get('id'),'int');
    $id_str = $id;
    //生成professional对象
$tb_pro = new IModel('professional'); if(!empty($id)) { $where = ''; $id_str = join(',',$id); $where = ' id in ('.$id_str.')'; //删除订单 $tb_pro->del($where); $this->redirect('expert_list'); } else { $this->redirect('expert_list',false); Util::showMessage('请选择要删除的数据'); } }

这个php写的就有点丑陋了。。。。。
学长说删除单条和删除多条可以写进一个函数中

if(is_array($id) && isset($id[0]) && $id[0]!='')
            {
                $id_str = join(',',$id);
                $where1 = ' id in ('.$id_str.')';
                $where2 = ' article_id in ('.$id_str.')';
            }
            else
            {
                $where1 = 'id = '.$id;
                $where2 = 'article_id = '.$id;
            }

这个看起来就舒服多了。

抢饭去咯~

 

 

posted on 2012-07-08 11:28  一个码菜  阅读(171)  评论(0)    收藏  举报