【发布时间】:2016-07-11 10:44:52
【问题描述】:
我想检查重复数据,当我在文本框中插入重复时它会显示重复,我尝试插入不重复显示“尝试获取非对象的属性”
控制器
public function gamecheck(){
$this->load->library('form_validation'); // load from validation
$this->form_validation->set_rules('gamename', 'Checkgamename', 'required');
if ($this->form_validation->run() == TRUE) {
if($this->input->post()) {
$this->load->model('game_m');
$gamepost = $this->input->post('gamename');
$getgame = $this->game_m->get_game($gamepost);
if($getgame->gamename!==''){
echo "duplicate";
}else{
echo "not duplicate";
}
}
}
$this->load->view('header');
$this->load->view('menu');
$this->load->view('game/gamecheck');
$this->load->view('footer');
}
型号
class Game_m extends CI_model{
public function get_game($gamepost) {
$this->db->from('game');
$this->db->where('gamename',$gamepost);
return $this->db->get()->row();
}
}
【问题讨论】:
-
$getgame 里面有什么,可以在这里回复吗?
-
$getgame 从模型 Game_m 中获取数据。在 get_game 函数中,我从数据库桌面游戏中选择数据,以便检查数据库中帖子和数据的值
标签: php activerecord codeigniter-3