dougong2306 2015-06-17 10:30
浏览 16

使用两列检查查询结果

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. 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']));

  2. Same No.1 but it should return false, because i put UniqueID that already has status = 1.

  3. Same As No.1 and 2, but this time i put the wrong uniqueID. eg. uniqueID is 1234567. it shoud return false because uniqueID is not true.

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'));
}
  • 写回答

1条回答 默认 最新

  • drf97973 2015-06-17 10:51
    关注

    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";
        }
    }
    
    评论

报告相同问题?