我正在尝试在管理面板上显示所有菜单。 我正在使用foreach循环来显示在数据库中输入的所有菜单。现在我想从菜单的foreach循环中的另一个表格中显示带有foreach循环的菜肴。
下面你可以找到我的foreach循环。
如何在div'panel-body'中添加另一个foreach循环,从$ menu ['ID']获取数据 每当我尝试这样做时,我都会收到未捕获错误:调用数组中的成员函数get_menu_items() 如何在数组上调用成员函数?
<?php foreach($menus as $menu): ?>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion-test" href="#<?php echo $menu['ID'] ?>" class="collapsed">
<?php echo $menu['title'] ?>
</a>
</h4>
</div>
<div id="<?php echo $menu['ID'] ?>" class="panel-collapse collapse">
<div class="panel-body">
<a href="deletemenu.php?id=<?php echo $menu['ID'] ?>">
<button type="button" class="btn btn-danger waves-effect waves-light w-xs m-b-5 pull-right" >Verwijder</button>
</a>
<a href="editmenu.php?id=<?php echo $menu['ID'] ?>">
<button type="button" class="btn btn-info waves-effect waves-light w-xs m-b-5 pull-right" style="margin-right: 5px;">Bewerken</button>
</a>
</div>
</div>
</div>
<?php endforeach; ?>
public function get_menu_items($id)
{
try
{
$stmt = $this->db->prepare("SELECT * FROM menu_items WHERE menu_id=:menu_id");
$stmt->execute(array(':menu_id' => $id));
$result = $stmt->fetch(PDO::FETCH_ASSOC);
return $result;
}
catch (PDOException $e)
{
echo $e->getMessage();
}
}
public function get_menu()
{
try
{
$stmt = $this->db->prepare("SELECT * FROM menu ORDER BY ID");
$stmt->execute();
return $stmt->fetchAll();
}
catch (PDOException $e)
{
echo $e->getMessage();
}
}