除了您的表设计登录之外,您还可以创建一个自定义回调函数来检查这些值在您的数据库中是否存在。验证将在您的 2 个字段之一中进行,例如 site_code:
public function _unique_code_no($site_code)
{
$CI =& get_instance();
$CI->form_validation->set_message('_unique_code_no', 'the values must be unique');
$site_no=$CI->input->post('id');
$query=$CI->db->query("select 1 from mytable where site_no=$site_no and site_code=$site_code");
if ($query->num_rows==0){
return TRUE;
}else{
return FALSE;
}
}
和验证规则:
$this->form_validation->set_rules('site_code', 'Site code', 'required|_unique_code_no');