SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast mildfoam's Avatar
    Join Date
    May 2010
    Location
    Australia.
    Posts
    56
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    [WTA] How to Create Dynamic Menu with PHP & MySQL? - simple version

    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 .

    is there any simple version of create dynamic menu with php and mysql?
    Object Oriented Programming Fans Boy ?

  2. #2
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    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 Code:
    <?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[url?>"><?php echo $menuitem[label?></a></li>

    <?php ?>

    </ul>
    <!-- close your menu html here -->

    </BODY>
    </HTML>

  3. #3
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Forgive me, late night posts never go as intended. Replace the foreach loop with a mysql_fetch_assoc loop and you're good. =)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •