I don't think it is very direct to filter the result set when sql is perfectly qualified to do such logic.
As Lodder corrected, you also need to use setQuery()
.
I've included some helpful diagnostic lines to help you to understand the query that is being generated and if there are any syntax errors, they will be displayed (so long as you don't run the redirect portion of your script).
After running my script, you may discover that:
- you have an sql error (for instance
userid
is not the same asuser_id
) - you don't actually have the
$joomlausers->id
value that you think you have - ...or something else that you haven't posted in your question is causing trouble
Please continue to edit your question and respond to requests for clarification so that this page can be resolved.
Untested Snippet:
try {
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select("COUNT(1)")
->from("#__rbid_users")
->where("userid = " . (int)$joomlausers->id);
JFactory::getApplication()->enqueueMessage($query->dump(), 'info');
// use only during debuggin -^^^^^^^^^^^^^^
$db->setQuery($query);
if (!$db->loadResult()) { // loadResult() should return either 0 or 1
// no error and no count, execute redirect
JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_something&view=something'));
} else {
// id matched
}
} catch (Exception $e) {
JFactory::getApplication()->enqueueMessage("Query Syntax Error: " . $e->getMessage(), 'error');
// use only during debugging -^^^^^^^^^^^^^^^^
}
It is important that I state that you must never show the exact query or error messages to the public as a matter of site security!
To be clear, the enqueueMessage()
calls are not required, they are just to assist your debugging.