I've created a function in Joomla. It checks if the given user's id exists in the database's table with an 'IF' statement. I think there's something wrong with the condition I'm using for the 'IF' statement.
Here's the code:
public function setRemainingPoints($userId,$points_taken)
{
$db =& JFactory::getDBO();
$query = ' SELECT '
.$db->nameQuote('remaining_points').' FROM '
.$db->nameQuote('#__remainingpoints').' WHERE '
.$db->nameQuote('user_id').'='.$userId;
$db->setQuery( $query );
if ($result = $db->query())
{
/* code if user found */
}
else
{
/* code if user not found */
}
return true;
}
Thanks in advance.
You need to get its number rows and make condition in this way
$db->setQuery($query);
$db->query();
$num_rows = $db->getNumRows();
if($num_rows>0){
// do something
}
else{
// do another things
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With