我是php的新手,它试图通过数据库(mysql)获取导航栏的数据,但显示如下:
允许的内存大小为134217728字节,已用尽(试图分配16384字节
<?php
$con=mysqli_connect("localhost","root","","menu");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Perform queries
function get_menu_tree($id)
{
global $con;
$menu = "";
$sqlquery = " SELECT * FROM mymenu";
$res=mysqli_query($con,$sqlquery);
while($row=mysqli_fetch_array($res,MYSQLI_ASSOC))
{
$menu ="<li><a href='".$row['link']."'>".$row['title']."</a>";
$menu = "<ul>".get_menu_tree($row['id'])."</ul>"; //call recursively
$menu = "</li>";
}
return $menu;
}
?>
<h1>Create Nested menu Tree by Mysql php</h1>
<ul class="main-navigation">
<?php echo get_menu_tree(1);//start from root menus having id 0 ?>
</ul>