Jump to content

[SOLVED] Dynamic Menu


Tripic

Recommended Posts

Ok so heres the problem and im still fairley new to php.
Im trying to build a completley dynamic menu system for my website using two tables
thae parent table being Modules and the child table being menu basically what i want to do
is for evry module that is set to be a menu and on the side of the page i tell it to it creates a table  as follows
[table]
[tr][td]Module Name[/td][/tr]
[tr][td]$menu here[/td][/tr]
[tr][td][/td][/tr][/table]

now basically I want it to take each module and create that table to where it has the module name ie. Header at
the top of the table and all menu items that are a child to that module in the second row . then i want th single blank row just for style purpouse before it moves on to do the same thing with the next module. Im assuming the best way to do this is with an array and all though i have a basic understanding of what the array does i havent got a clue how to use it and reading the php bible to figure it out is just confusing me so im hoping some one can show me a simple example that i can work off of or if im wrong and going about this all wrong smack me around a bit and get me set strait. any help is greatley apreciated.. Tripic
Link to comment
Share on other sites

This wont setup the tables how you want, but it should give you a good start.

[code]
<?php
    // connect to db.
    $sql = "
        SELECT
            mods.modname AS mname,
            child.childname AS cname
        FROM
            mods,child
        WHERE
            mods.id = child.modid;";

    if ($result = mysql_query($sql)) {
        if (mysql_num_rows($result)) {
            $mname = '';
            while ($row = mysql_fetch_assoc($result)) {
                if ($row['mname'] != $mname) {
                    $mname = $row['mname'];
                    echo "<h1>$mname</h1><br />";
                } 
                echo $row['cname']."<br />";
            } 
        } 
    }  else {
      echo "Query failed ".mysql_error();
    }
?>
[/code]

If you really need help setting up the tables you'll need to be a little clearer with your explination sorry.
Link to comment
Share on other sites

ok right now its poping up the module name for each menu item so the module name keeps coming up over and over i only want it to sho up once hers a pic so you can see what its doing now
[URL=http://img236.imageshack.us/my.php?image=example1nm4.jpg][IMG]http://img236.imageshack.us/img236/5189/example1nm4.th.jpg[/img][/URL]

heres the modified vertion of your code that i adapted to get it to work like this
[code]
<?php require_once('../Connections/TEst.php'); ?>
<?php
mysql_select_db($database_TEst, $TEst);
?>
<?php
    // connect to db.
    $sql = "
        SELECT
            brg_modules.Module_Name AS mname,
            brg_menu.title AS cname,
brg_menu.icon AS cimg,
brg_menu.url AS curl
        FROM
            brg_modules,brg_menu
        WHERE
            brg_modules.id = brg_menu.module;";

    if ($result = mysql_query($sql)) {
        if (mysql_num_rows($result)) {
            $mname = '';
            while ($row = mysql_fetch_assoc($result)) {
                if ($row['mname'] != $mname) {
                    $mname = $row['mname'];
$cname = $row['cname'];
$curl = $row['curl'];
                    echo "<table><tr><td>$mname</td></tr>";
                } 
                echo "<tr><td><ahref='$curl'>$cname</a></td></tr><tr><td>&nbsp;</td></tr></table>";
            } 
        } 
    }  else {
      echo "Query failed ".mysql_error();
    }
?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.