Your getnews() function only ever returns a single row from the database, even though your query will fetch them all.... perhaps consider a loop in the getnews() function that returns each one in turn, maybe using a generator so that you can use them in a foreach loop
function getnews() {
global $db;
$news=$db->query("select * from news order by news_id desc");
while ($row=$news->fetch_object()) {
yield $row;
}
}
foreach (getnews() as $result) {
echo $result->news_title . "<br>";
}
Though using a generator does require PHP >= 5.5
If you're using an earlier version of PHP, then build an array in getnews() and return that, but it isn't as efficient:
function getnews() {
global $db;
$news=$db->query("select * from news order by news_id desc");
$items = array();
while ($row=$news->fetch_object()) {
$items[] = $row;
}
return $items;
}
foreach (getnews() as $result) {
echo $result->news_title . "<br>";
}