【问题标题】:How to check email already exist in multiple table in codeigniter如何在codeigniter的多个表中检查电子邮件是否已存在
【发布时间】:2017-03-03 12:54:55
【问题描述】:

控制器代码
如何检查codeigniter中多个表中是否已存在电子邮件

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;

       } 
 }

【问题讨论】:

    标签: php mysql codeigniter activerecord


    【解决方案1】:

    您可以使用 OR 条件来检查多个表中的电子邮件。

    $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); 
    

    希望这会对你有所帮助。

    【讨论】:

      【解决方案2】:

      更改您的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";
          }   
      
      }
      

      【讨论】:

      • 没明白你的意思
      • 在将新电子邮件插入数据库表之前,我需要检查电子邮件是否存在于两个不同的表中
      • 是的,所以在我的代码中它可以存档,在控制器 echo "New Email"; 中删除它并添加插入功能
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-13
      • 2020-02-27
      • 2014-03-15
      • 2017-01-28
      • 1970-01-01
      相关资源
      最近更新 更多