當我嘗試print_r($結果)它獲取數組。數組([0] =>數組([id] => 6 [0] => 6 [ref] => GSO 646 & 647 [1] => GSO 646 & 647)[1] => ] => 7 [0] => 7 [ref] => GSO 962 [1] => GSO 962)[2] =>陣列([id] => 8 [0] => 8 [ref] => GSO ASTM F 1923 [1] => GSO ASTM F 1923)錯誤獲取我的數組MVC
但我有一個錯誤,也許錯誤是在foreach,因爲它說無效的供應foreach()。任何人都可以幫我嗎?謝謝你
模型
require_once("DatabaseManager.php");
class Model
{
public $connection;
public function __construct(){
$connection = new DatabaseManager();
$this->connection = $connection->getConnection();
}
public function getAllRecords()
{
$sql = "SELECT * FROM reference";
$query = $this->connection->query($sql);
$result = $query->fetchAll();
//print_r($result);
}
}
控制器
require_once("../model/Model.php");
class Controller
{
private $model;
public function __construct()
{
$this->model = new Model();
}
public function displayAllRecords()
{
$result = $this->model->getAllRecords();
return $result;
}
}
VIEW
require '../controller/Controller.php';
$controller = new Controller();
foreach($controller->displayAllRecords() as $records) {
.
.
}
你必須渲染或拋從控制器東西來查看。 –
你是什麼意思@SaugatBhattarai?我試圖把返回$結果;仍然有錯誤 –
Array([0] => Array([id] => 6 [0] => 6 [ref] => GSO 646&647 [1] => GSO 646&647)[1] => Array([id ] => 7 [0] => 7 [ref] => GSO 962 [1] => GSO 962)[2] =>陣列([id] => 8 [0] => 8 [ref] => GSO ASTM F 1923年[1] => GSO ASTM F 1923)時,我的print_r($結果); –