2016-12-28 108 views
1

我有两个表供应商和用户。我们如何验证电子邮件存在两个表。我如何验证电子邮件存在两个表中的电子邮件

$this->form_validation->set_rules('email', 'Email', 'required|is_unique[user.email]|valid_email','call_back_mail',array('required' => 'You have not provided %s.', 'is_unique' => 'This %s already exists.')); 
+0

使用回调函数 –

回答

1
Add this in your .php file (controller) 
$form_validation->Form_validation($emails,'Email',"require|validemail|check_unique-admin_details-users_details-email"); 

//and add this code in the validation.php (library) 
case "check_unique": 
        $result= $this->validation_check_unique($data,$name,$key1[1],$key1[2],$key1[3]); 
        break; 

// 
function validation_check_unique($data="",$name,$table,$table1,$fieldname) 
    { 

     $sql = mysql_fetch_array(mysql_query("select $fieldname from $table where $fieldname = '$data'")); 
     if($data == $sql[0]) 
     { 
      $sql1 = mysql_fetch_array(mysql_query("select $fieldname from $table1 where $fieldname = '$data'")); 
      if($data == $sql1[0]) 
      { 
       array_push($this->validation_array,"<i class='fa fa-arrow-circle-right'></i> $name already exist."); 
       return FALSE; 
      } 

     } 

    } 
0

我不undrestend如果供应商和用户表是PHP数组或SQL表?