I use the following function to check if there are any new news items:
function get_news(){
$cn = "SELECT MIN(news_id) AS news_id
, news_title
FROM news
WHERE isNew = ?";
$chNew = $this->pdo->prepare($cn);
$chNew->execute(array($isNew));
$res_new = $chNew->fetch();
$return = '';
if (empty($res_new)){
echo "There are no new news items";
}else{
$chNew = $this->pdo->prepare($cn);
$chNew->execute(array($isNew));
while($row = $chNew->fetch(PDO::FETCH_OBJ)) {
$return .= '<p>'.htmlspecialchars($row->news_title).'</p>';
}
return $return;
}
When executing the page while there are new news items I get the following error:
Undefined property: stdClass::$news_title
What should I do to avoid that?