Unknown error

I’m trying to make a menu like this (view menu). Here is the code:

<?php
require_once "conf.php";
dbConnect();
?>
<head>
<link rel="stylesheet" type="text/css" href="http://grimon.net/css/jqueryslidemenu.css" />    
<script type="text/javascript" src="https://grimon.net/js/jquery.js"></script>
<script type="text/javascript" src="https://grimon.net/js/jqueryslidemenu.js"></script>
</head>
<div id="myslidemenu" class="jqueryslidemenu">  
<ul>
<?php
function menu($id) {
$zapros=mysql_query("select * from menu where Id_id={$id}") or die (mysql_error());
while ($row=mysql_fetch_array($zapros)){
//echo "<div id="myslidemenu" class="jqueryslidemenu">";
//echo "<ul>"
echo "<li><a href='#'>{$row['name']}</a></li><ul>";
menu ($row['id']);
echo "</ul>";
}
}
echo "<ul>";
menu (0);
echo "</ul>";
?>
</div>
</ul>

In chrome it doesn’t show anything at all, but in mozilla it shows a normal menu. And it’s not dynamic at all. Although when viewing the page code in both chrome and mozilla it says:

<head>
<link rel="stylesheet" type="text/css" href="http://grimon.net/css/jqueryslidemenu.css" />    
<script type="text/javascript" src="https://grimon.net/js/jquery.js"></script>
<script type="text/javascript" src="https://grimon.net/js/jqueryslidemenu.js"></script>
</head>
<div id="myslidemenu" class="jqueryslidemenu">  
<ul>
<ul><li><a href='#'> 1</a></li><ul><li><a href='#'> 11</a></li><ul></ul><li><a href='#'> 22</a></li><ul></ul></ul></ul></div>
</ul>

What could be wrong?


Answer 1, authority 100%

And it was not my destiny to knock, since you use an example from my site? :-))) I’ll get free and knock on the agent, I’ll show you what’s wrong with you. )) The selection is not entirely acceptable and the list view is not correct (several uls are open in a row – chrome will not understand this).

And we must take into account the fact that if you are already making calls to each item, then you are doing 2 functions. The first takes the item, and the second looks to see if it has sub-items. But for now, I can say one thing – the base for the menu you have is not particularly well done.


Answer 2, authority 50%

<ul>
<ul><li><a href='#'> 1</a></li><ul><li><a href='#'> 11</a></li><ul></ul><li><a href='#'> 22</a></li><ul></ul></ul></ul>

You need it a little differently. In such jquery menus, it is necessary that all submenus (<ul>) are contained in the item that called it (li). Otherwise, the whole meaning is lost. Those. you need to achieve the code:

<ul><li><a href='#'> 1</a><ul><li><a href='#'> 11</a></li><li><a href='#'> 22</a></li></ul></li></ul>

Added.

Something like this:

<?php
function menu($id) {
$zapros=mysql_query("select * from menu where Id_id={$id}") or die (mysql_error());
if(mysql_num_rows($zapros)){
echo "<ul>";
while ($row=mysql_fetch_array($zapros)){
echo "<li><a href='#'>{$row['name']}</a>";
menu ($row['id']);
echo "</li>";
}
echo "</ul>";
return 1;
}
else return 0;
}
menu (0);
?>

But then again… It’s better to first select all the records from the table, and then parse them using php, so as not to load the skule server. It takes a lot of time for each of your database queries. If, for example, your menu will be loaded simultaneously by 50 users, then the server will simply suffocate … Again, it depends on the number of items and on the server, but why waste server resources once again, which are usually few? ..