I need pass array from m.php back to index.php and loop to print each row, but I can't find way how to do it? any suggestion will be appreciated.
below code I use return $rows in m.php but index.php can't get it..
index.php
<?php
require 'm.php';
$select_news = new select_news();
$select_news->select_3();
print_r($rows);
foreach ($rows as $row){
?>
<div><?=$row['id']?></div>
...
<?php
}
?>
m.php
class select_news{
public function select_3(){
global $db;
$sth = $db->prepare('SELECT * FROM news ORDER BY id DESC LIMIT 3');
$sth->execute();
$rows = $sth->fetchAll();
return $rows;
}
}