Sunday 4 December 2016

php - Fatal error: Call to a member function fetch_assoc() on a non-object -

I'm trying to execute a query but keep getting an error Fatal error: Call to a member function fetch_assoc() on a non-object. I have searched through forums for answers but i'm very new to php and a lot of the stuff I found is very advanced for me to get my head around. I'm working with Joomla, the connection to the database is working and I can successfully write to the table I am working with but can't select the information from it without getting this error.




                    $message = '';
$db = JFactory::getDBO();
if($db->connect_error)
{
//if error assign to message
$message = $db->connect_error;
}
else

{
$sql = 'SELECT * FROM jos_offer';
$result = $db->query($sql);
if($db->error)
{
$message = $db->error;
}
else
{
while($row = $result->fetch_assoc())

{
echo '
'.$row['student_id'].$row['offer'].'
';
}
}
}
?>

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...