目前,我的潛在客戶頁面有一個名為 crm_leads 的表,其中我已經有很多記錄。現在對于同一個頁面,我創建了幾個新欄位,這些欄位現在將存盤在另一個名為 crm_leads_details 的表中。現在我以陣列格式存盤我所有的 POST 值,如下所示:
$main=array(
'priority'=>$this->input->post('priority'),
'lead_status'=>$this->input->post('lead_status'),
'comment'=>$this->input->post('comment'),
'sub_status'=>$this->input->post('sub_status'),
'lead_agent'=>$this->input->post('lead_agent'),
'emailopt'=>$this->input->post('emailopt')=='Y' ?'Y':'N',
// 'kitchen'=>$this->input->post('kitchen')
);
$loginid=$this->leads_model->update_lead($main,$id);
現在在我的模型中,我嘗試使用此陳述句來更新我的兩個表,但它不起作用:
function update_lead($maindata,$id,$w=false)
{
if($w==true){
$cond=$id;
}
else{$cond['id']=$id;}
$sql = "UPDATE `crm_leads` LEFT JOIN `crm_leads_details` ON `crm_leads`.`id`=`crm_leads_details`.`leads_id`
SET ".$maindata." WHERE ".$cond;
$query = $this->db->query($sql);
print_r($this->db->last_query()); die();
return $query;
}
這給出了以下輸出 UPDATE crm_leads LEFT JOIN crm_leads_details ON crm_leads.id=crm_leads_details.leads_id SET Array WHERE Array
此外,由于 crm_leads_details 是一個新表,因此當前沒有記錄,因此不確定是否LEFT JOIN crm_leads_details ON crm_leads.id=crm_leads_details.leads_id可以在這里使用
uj5u.com熱心網友回復:
像這樣寫查詢
$sql = "UPDATE `crm_leads` LEFT JOIN `crm_leads_details` ON `crm_leads`.`id`=`crm_leads_details`.`leads_id`
SET ";
$i = 0;
foreach($maindata as $key=>$value) {
$i ;
$sql .= $key." = ".$value;
$sql .= ($i == count($maindata)) ? "" : " , " ;
}
$sql .= " WHERE ".$cond;
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/416832.html
標籤:
下一篇:使用mysql根據排名分配獎品
