这是表结构。
++++++++++++++++++++++++++++++++++++++++++++++
+ No + UniqueID + Email + Status +
+ 1 + 1q2w3e4r + myemail@gmail.com + NULL +
+ 2 + 12345qwe + myemail@yahoo.com + 1 +
++++++++++++++++++++++++++++++++++++++++++++++
逻辑应该是:
我想输入UniqueID
和Email
。当我将值设为1q2w3e4r
和Email
myemai@gmail.com
时,它会返回True或将uniqueID作为响应,如下所示:
$ this-> response(array('2'=> $ data ['UniqueID']));
相同的No.1但是它应该返回false,因为我已经UniqueID
已经有status = 1
。
与No.1和2相同,但这次我错了uniqueID
。例如。 uniqueID是1234567.它应该返回false,因为uniqueID不正确。
我的代码如下所示:
=============================================== ========================== 通过修改以下代码解决问题:
模型
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;
}
和我的控制器如下:
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'));
}
答案 0 :(得分:1)
有点难以理解你。但我相信你正在寻找这样的东西。请尝试以下方法:
首先,将模型方法更改为:
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();
}
然后在你的控制器中:
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";
}
}