To get your desired output you just need to change your loop to this:
foreach($results as $row) {
echo 'TITLE: ' . $row->posttitle . '<br>';
echo 'AUTHOR: ' . $row->postauthor . '<br>';
echo 'DATE CREATED: ' . $row->postdate . '<br>';
echo 'MESSAGE: ' . $row->message . '<br>';
}
If you really want to make Templates
, you should take a look at some templating-languages like Twig
. https://twig.symfony.com/