需要一些关于检查数据是否已经存在于数据库中的帮助,系统将显示提示。所以这是代码:
在模型中:
public function check_name($str, $col)
{
$lname = $this->input->post('lastname');
$fname = $this->input->post('firstname');
$result = $this->db->get_where('patients', array(
'firstname' => $lname ,
'lastname' => $fname
));
if($result->num_rows() > 0){
// $this->form_validation->set_message('check_name', 'The %s field already exists.');
echo "Patient with the same name already exists.";
} else {
return true;
}
}
在我的 Controller 中调用它的正确方法是什么。上面的代码似乎不起作用。
最佳答案
您的函数中有两个未在任何地方使用的参数。尝试这样做:
public function check_name($firstname, $lastname)
{
/*
$firstname = $this->input->post('lastname');
$lastname = $this->input->post('firstname');
*/
$query = $this->db->query("SELECT firstname, lastname FROM patients WHERE firstname = ".$firstname." AND lastname = ".$lastname." ");
if($query->num_rows() == 0){
// $this->form_validation->set_message('check_name', 'The %s field already exists.');
echo "Patient with the same name already exists.";
} else {
return true;
}
}
关于php - 在 codeigniter 中发现数据库中有重复数据后显示提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33296398/