2017-03-03 83 views
-1

控制器代碼
如何檢查電子郵件已經存在於多個表中笨如何檢查電子郵件在多個表中笨已經存在

function rolekey_exists($key) { 
    $this->Register_model->mail_exists($key); 
} 

型號代碼

下方所示型號代碼我加入了兩張表如何在插入兩張不同的表之前查看郵件已存在

function mail_exists($key) 
{ 
$this->db->select('*'); 
$this->db->from('supplier_registration'); 
$this->db->join('customer_registration', 'supplier_registration.email = customer_registration.email'); 
$this->db->where('supplier_registration.email',$key); 

$query=$this->db->get(); 
if ($query->num_rows() > 0){ 
     return true; 

      } 
    else { 

     return false; 

     } 
} 

回答

1

您可以使用或使用條件在多個檢查電子郵件表。

$this->db->select(*); 
$this->db->->from('supplier_registration, customer_registration'); 
$this->db->where('supplier_registration.email',$key); 
$this->db->or_where('customer_registration.email',$key); 

希望這會幫助你。

0

改變你在控制器TRUEFALSE以及檢查

在型號

function mail_exists($key) 
{ 
    $this->db->select('*'); 
    $this->db->from('supplier_registration'); 
    $this->db->join('customer_registration', 'supplier_registration.email = customer_registration.email'); 
    $this->db->where('supplier_registration.email',$key); 

    $query = $this->db->get(); 
    if ($query->num_rows() > 0) 
    { 
     # email exist 
     return false; 

    } 
    else { 
     # new/fresh email 
     return true; 

    } 
} 

在控制器

function rolekey_exists($key) { 
    $result = $this->Register_model->mail_exists($key); 

    if ($result == TRUE) { 
     echo "Email Exists"; 
    } else { 
     echo "New Email"; 
    } 

} 
+0

沒有得到你的意思 –

+0

之前插入新的電子郵件到數據庫表我需要檢查電子郵件存在或不在兩個不同的表 – Learner

+0

亞所以在我的代碼它可以存檔,在控制器'回聲「新電子郵件」;'刪除此並添加插入功能 –

相關問題