简体   繁体   English

用两列检查查询结果

[英]Check query result with two column

Here is the table structure. 这是表格结构。

  ++++++++++++++++++++++++++++++++++++++++++++++
  + No + UniqueID + Email             + Status +
  + 1  + 1q2w3e4r + myemail@gmail.com + NULL   +
  + 2  + 12345qwe + myemail@yahoo.com + 1      +
  ++++++++++++++++++++++++++++++++++++++++++++++

The logic should be: 逻辑应为:

  1. I want to input UniqueID and Email . 我想输入UniqueIDEmail When I put the value is 1q2w3e4r and Email myemai@gmail.com , it shoudl return True or put the uniqueID as response like this one below: $this->response(array('2' => $data['UniqueID'])); 当我将值设置为1q2w3e4r并发送Email myemai@gmail.com ,它应返回True或将uniqueID作为如下所示的响应:$ this-> response(array('2'=> $ data ['UniqueID'] ));

  2. Same No.1 but it should return false, because i put UniqueID that already has status = 1 . 相同的No.1,但它应该返回false,因为我放置了已经具有status = 1 UniqueID

  3. Same As No.1 and 2, but this time i put the wrong uniqueID . 与1号和2号相同,但是这次我输入了错误的uniqueID eg. 例如。 uniqueID is 1234567. it shoud return false because uniqueID is not true. uniqueID为1234567。由于uniqueID不为true,因此应返回false。

And my code looks like this below: 我的代码如下所示:

========================================================================= Solve The Problem by modify this code below: ================================================== =======================通过修改以下代码来解决问题:

Model 模型

  public function signup($data)
  {
    $this->db->select("status");
    $this->db->from("mytable");
    $this->db->where("UniqueID ", $data['UniqueID ']);
    $this->db->where("email", $data['email']);
    $q = $this->db->get();
    return $q;
  }

and my controller like this below: 和我的控制器如下所示:

if($result->num_rows() > 0) {
  $s = $result->row()->status;
  if (isset($s) && $s == 1)
  {
    $this->response(array('1' => 'missing data'));
  } else if(!isset($s)){
    $this->response(array('2' => $data['nopolis']));
  }
} else {
  $this->response(array('3' => 'missing'));
}

Kind of hard to understand you. 有点难以理解你。 But I believe you are looking for something like this. 但我相信您正在寻找类似的东西。 Try the following: 请尝试以下操作:

First, change your model method to this: 首先,将模型方法更改为:

public function signup($data){
    $this->db->select("status");
    $this->db->from("mytable");
    $this->db->where("uniqueID", $data['uniqueID ']);
    $this->db->where("email", $data['email']);
    $q = $this->db->get();
    return $q->row();
}

Then in your controller: 然后在您的控制器中:

public function validation_post(){
    $data = array (
        'uniqueID' => $this->input->get_post('nopolis')
    );

    $result = $this->signup->signup($data);
    $s = $result->status;
    if ($result) {
        $s = $result->status;
        if (isset($s) && $s == 1) {
            //Condition where status = 1
        } else if (!isset($s)) {
            //Condition where status = NULL
        } else {
            //Condition where status is something else
        }
    } else {
        //Condition where id and email does not exist
        echo "No Results";
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM