CodeIgniter Forums
Call to a member function num_rows() on a non-object - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Call to a member function num_rows() on a non-object (/thread-21797.html)

Pages: 1 2


Call to a member function num_rows() on a non-object - El Forum - 09-05-2009

[eluser]Zorancho[/eluser]
Try using this:
Code:
function compare($fid, $uid)
{
    $fid = (int) $fid;
    $uid = (int) $uid;
    $sql = "SELECT * FROM friends_list WHERE approved_status = 'yes' AND user_id=".$uid." AND friend_id=".$fid." OR
    (friend_id=".$uid." AND user_id=".$fid.") LIMIT 1";
    $q = $this->db->query($sql);
    if($q->num_rows() > 0)
    {
        return true;
    }
    return false;
}
It worked for me


Call to a member function num_rows() on a non-object - El Forum - 09-05-2009

[eluser]Zorancho[/eluser]
After this line
Code:
$userId = (trim($userId) == '') ? $this->session->userdata('user_id') : $userId;

Check if the $userId is empty string
Code:
if($userId == '')
return false;
That's your problem in your query.