php function getNews sql SELECT msgs id as id title category name as c

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
function getNews(){
$sql = "SELECT msgs.id as id, title, category.name as category, description, source, datetime
FROM msgs, category
WHERE category.id = msgs.category
ORDER BY msgs.id DESC";
$result = $this->_db->query($sql);
$arr = [];
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$arr[] = $row;
}
return $arr;
}
if ($items == $news->getNews()) {
foreach ($$items as $item) {
$date = date("d-m-Y",$item['datetime']);
echo <<<NEWS
<h3>{$item[title]}</h3>
<strong>$date</strong>
<a href="{item[source]}">{$item[source]}</a>
<p>{$item[description]}</p>
NEWS;
}
}
?>