我有:
function check_if_loggedin(){
#get user session id from db.
$sess = $this->session->userdata('session_id');
#set numerical value of successfully logged in equal 1
$loggedInSetSuccess = 1;
#compare session id to match in db (can only have only 1 match)
$sessionsDbCompare = $this->db->get_where('Client',array('session_id'=>$sess,'loggedIn'=>$loggedInSetSuccess));
if($this->db->num_rows($sessionsDbCompare) == 1) {
# User has valid session(valid sessID+loggedIn=0, show welcome
#show account settings with primary nav
$this->load->view('v/supernavigationloggedin.php');
$this->load->view('v/primarynavigation.php');
}
else{
# user doesnt have both a valid session and loggedIn is set to 0, show login form
#show login form with primary nav
$this->load->view('v/supernavigationnotloggedin.php');
$this->load->view('v/primarynavigation.php');
}
}
但我收到错误:
Fatal error: Call to undefined method CI_DB_mysql_driver::num_rows()
在以下一行:
if($this->db->num_rows($sessionsDbCompare) == 1) {
我确认数据库是在autoload.php中加载的,并且活动记录肯定已打开。
我在这里做错了什么?
答案 0 :(得分:3)
将该行更改为:
if($sessionsDbCompare->num_rows() == 1) {