这是表格结构。
++++++++++++++++++++++++++++++++++++++++++++++
+ 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,因为我放了已经有
status = 1
UniqueID
.与 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'));
}
有点
难以理解你。但我相信你正在寻找这样的东西。请尝试以下操作:
首先,将模型方法更改为:
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";
}
}