hi folk,
I am currently developing my own CMS that face with one problem that i couldn’t solve in few days lately. I have read this article Sitepoint Dynamic Menu and another resource from stackoverflow. But, when i learn and read more and more over i just feel more dummies :mad:.
is there any simple version of create dynamic menu with php and mysql?
This depends on a lot actually. Too much to create a single simple script for. The things you’ll need to look at are:
How are the menu items defined? (in database, in file, is the data a serialized object array or a CSV list, etc…)
What elements do I need to actually create a menu item? (url, target, label, etc…)
Do I want the PHP script to generate the entire html structure for the menu, or is it just a JSON result to be consumed by a jquery routine?
Other than that, you just pull the required info from storage and assemble the menu.
Now, if your question was actually about how to make a basic dynamic popup menu, you need to ask this in the CSS forum.
An example showing how to read from a db:
<?php
require_once('includes/engine.php');
// sample, don't actually use *, but a field list
$menuitems = mysql_query("select * from menuitems");
// test results. if no results die(), otherwise allow html to process
?>
<HTML>
<HEAD><TITLE>foo</TITLE></HEAD>
<BODY>
<!-- open your menu html here -->
<ul>
<?php foreach ($menuitems as $menuitem) {?>
<li><a href="<?php echo $menuitem ?>"><?php echo $menuitem[label] ?></a></li>
<?php } ?>
</ul>
<!-- close your menu html here -->
</BODY>
</HTML>
Forgive me, late night posts never go as intended. Replace the foreach loop with a mysql_fetch_assoc loop and you’re good. =)