如何排除表字段MYSQL

时间:2012-02-13 23:27:34

标签: php mysql field

对于奇怪的标题感到抱歉,但如果用户类型为2或3,我遇到一个小问题,那么我需要用户不能插入或更新几个字段,而不是创建一些插入查询下面列出了一些我不需要更新的字段。

  

AMStatus,HQStatus,approvedforsite

public function databaseinsert($data)
    {
        $this->data = $data;
        switch($this->data['action']){
            case "newlead":
                $this->insert("customer_detail",
                              "TradingName,Street,City,State,PostCode,Industry,SubCategories,Membership,LeadStatus,AMStatus,HQStatus,approvedforsite,Salutation,FirstName,LastName,Website,Company,ABN_ACNNumber,Phone,Mobile,Notes,Description",
                              "'{$this->data['tradingname']}',
                              '{$this->data['street']}',
                              '{$this->data['suburb']}',
                              '{$this->data['state']}',
                              '{$this->data['postcode']}',
                              '{$this->data['category']}',
                              '{$this->data['subcategory']}',
                              '{$this->data['membership']}',
                              '{$this->data['salestatus']}',
                              '{$this->data['managerstatus']}',
                              '{$this->data['hqstatus']}',
                              '{$this->data['publishtoweb']}',
                              '{$this->data['title']}',
                              '{$this->data['firstname']}',
                              '{$this->data['lastname']}',
                              '{$this->data['webaddress']}',
                              '{$this->data['companyname']}',
                              '{$this->data['abnacn']}',
                              '{$this->data['phonenumber']}',
                              '{$this->data['mobile']}',
                              '{$this->data['notes']}',
                              '{$this->data['businessdescription']}'                              
                              ");
            break;
        }

    }

1 个答案:

答案 0 :(得分:1)

您需要通过应用条件在脚本句柄数据库字段和值中执行此操作。并在$this->insert函数中应用它们之前,根据不同的用户类型创建两者的字符串。

如下所示:

if($usertype=='yourtype')
{
$fieldsstr="TradingName,Street,City.................";
$valuestr=$this->data['tradingname'].",".$this->data['field2'].",".......

}
else
$fieldsstr="TradingName,Street.................";
$valuestr=$this->data['tradingname'].",".$this->data['field2'].",".......

}

 $this->insert("customer_detail",$fieldsstr,$valuestr);