Check if User logged in ? solved

Hi,
I've simple question: why it doesn't work ?

I have two calc element :
one : get the user id of a selected user : OK!

$requiredId = '{demande___ask_required_raw}';
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery->select('user_id')->from('utilisateurs')->where('id = ' . $myDb->quote($requiredId));
$myDb->setQuery($myQuery);
return $myDb->loadResult();

A second check if the user is logged in:

$user_id = '{demande___userid_selected}';
echo "$user_id"; (just to check if the value is loaded: OK! )
$db =& JFactory::getDBO();
$db->getQuery(true);
$query = 'SELECT COUNT(userid) FROM #__session WHERE userid = "$user_id"';
$db->setQuery($query);
$loggedin = $db->loadResult();
if($loggedin){
return "online.";
} else {
return "offline";
}

But it always return "offline" and the userid is loaded
It return 882offline
If I set the value: $query = 'SELECT COUNT(userid) FROM #__session WHERE userid = 882'
it's OK!

What i forgot ?

Regards,
 
I think it is the quoting you are using. Change it to WHERE userid='.$user_id;

You can also echo $query; to confirm what the select is actually creating.
 
Hi,
thanks
already tried but it return error sql that's why i've tried in this way
echo $query return : SELECT COUNT(userid) FROM #__session WHERE userid="$user_id"
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top