[英]Verify count_all_results = 1 in CodeIgniter
I'm trying to accomplish getting the current users session (if it exists) then comparing it to the database, along with a loggedIn value = 1 (meaning loggedIn) and count that a single row exists matching this where clause. 我试图完成获取当前用户会话(如果存在的话),然后比较它的数据库,用的loggedIn值一起= 1(指的loggedIn),并认为这是一种单一的行存在匹配此where子句。 If that exists, show logged in, else, show login form (shown in
if{}
else{}
below) 如果存在,则显示已登录,否则,显示登录表单(显示在下面的
if{}
else{}
中)
I have a model with a function: 我有一个带有功能的模型:
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($sessionsDbCompare->count_all_results() = 1) {
# User has valid session(valid sessID+loggedIn=0, show welcome
echo 'Logged in baby';
# show account pref
}
else{
# user doesnt have both a valid session and loggedIn is set to 0, show login form
echo 'login form here';
}
}
The problem is - if($sessionsDbCompare->count_all_results() = 1) {
my IDe is warning me, should I be using count_all_results() == 1
or count_all_results() === 1
. 问题是
if($sessionsDbCompare->count_all_results() = 1) {
我的IDe警告我,我应该使用count_all_results() == 1
还是count_all_results() === 1
。 Sorry this is slightly newbie, I guess I'm a little confused because count_all_results() is a function. 抱歉,这有点新手,我想我有些困惑,因为count_all_results()是一个函数。 (I do understand comparison operators like "1" == "01")
(我了解比较运算符,例如“ 1” ==“ 01”)
You should use ==
so the if statement would look like: 您应该使用
==
以便if语句如下所示:
if($sessionsDbCompare->count_all_results() == 1) { ...
You can always use var_dump($sessionsDbCompare->count_all_results());
您可以随时使用
var_dump($sessionsDbCompare->count_all_results());
or similar to check the value returned... 或类似的检查返回的值...
You should be using this 你应该用这个
count_all_results() == 1
The way you have it is assigning 1 to what is left of it 您拥有的方式是将 1 分配给剩余的内容
The IDE is also worried that count_all_results() might return false and 0. That's why it is suggesting the three === but dont worry about that. IDE还担心count_all_results()可能返回false和0。这就是为什么它建议使用三个===而不用担心的原因。 The two equals will fix it
两个等于将解决它
This line: 这行:
if($sessionsDbCompare->count_all_results() = 1) {
Should be: 应该:
if($sessionsDbCompare->count_all_results() == 1) {
您应该使用$ this-> db-> count_all()而不是$ this-> db-> count_all_results()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.