mysqli returning single result

I'm trying to convert some code over to mysqli from my sql but getting the error:
Fatal error: Call to a member function fetch_assoc() on a non-object in /home/prod/public_html/dashboard/leftsidebar.php on line 8

Not sure what I'm doing wrong, just trying to pull the count number.  Below is my code.

//Project Count
$sql1 = "select count( as projecttotal from projects p inner join projectassoc pa on = pa.project_id where pa.user_id = $userid";
$result1 = $db->query($sql1);
$row1 = $result1->fetch_assoc();
echo $row1['projecttotal'];

Open in new window

LVL 12
Nathan RileyFounderAsked:
Who is Participating?
Ray PaseurConnect With a Mentor Commented:
This almost always means the query failed.  This article shows how to visualize error information.
Nathan RileyFounderAuthor Commented:
Checked the query in phpmyadmin and it worked.
Nathan RileyFounderAuthor Commented:
Heh, it's been a long day.  Had an issue with the connection to DB.  All working now thanks.
Ray PaseurCommented:
Great!  Thanks for the points, ~Ray
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.