This doesn't look easy and I don't have time to sit down and think about it
but I'll give a couple of suggestions.

1. An ORDER BY clause may help.  When you go through the list, you will then
need to detect a change in "menu level".

2. Why do the menu items need to be in a database anyway?  Just have
"static" menus in your web pages.  There are a number of ways to bring up
menu items, as you described, using javascript:

----- Original Message -----
From: "David" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, April 12, 2001 8:59
Subject: MySQL and PHP issue


> I tried posting this in the PHP newsgroup but received no response so
> thought I would try here since issue involves MySQL
>
> I am trying to make a simple HTML menu system with data stored in a
> MySQL database.. I am having problems displaying menu links under the
> correct submenu from a loop.
>
> I have a database with two tables. One table holds menu and sub menu
> headings and
> the other table holds the contents of each submenu (the actual menu
> links and
> names).  I need to display the menu title and then the sub menu title
> from table 1 and
> then display the submenu contents or links from table 2 and then display
> the next set
> of links under the correct submenu
>
> Example output would look like this:
>
> Say person clicks on Admin menu which is already displayed then the
> networking
> submenu heading will display along with the submenu links:
>
>    Example:   Admin                            (main menu title from db
> table 1)
>                         Networking                (submenu title , from
> db table 1
>                                 ping                    (Link to ping
> from db table 2)
>                                 traceroute           (Link to ping from
> db table 2)
>                                 nsloopup etc........
>
>
> I don't know how to go about outputing the links under the correct
> submenu.  The
> main menu is no problem. I am thinking I would need a loop within a
> loop.
>
> The query I use: $query = "SELECT * FROM menutable, elementstable WHERE
> menutable.menutable_id = elementstable.menuid AND menutable.mainmenu =
> 'Admin' ";
>
> $result = mysql_db_query("menus", $query);
>
> This loop simply assigns variables and prints out all output under the
> main menu
> called Admin.  The problem is how do I display
>
>   while ($r = mysql_fetch_array($result)) {
>
> // start menu table (table holds main menu/sub menu headings
>             $menutable_id = $r["menutable_id"];
>             $menunumber = $r["menunumber"];
>             $mainmenu = $r["mainmenu"];
>             $submenu = $r["submenu"];
> // start elements table (table that holds the links and names of each
> link)
> // element_id references menu table
>             $element_id  = $r["element_id"];
>             $element = $r["element"];
>             $url = $r["url"];
>             $menuid = $r["menuid"];
>
> // next display data this is wrong cause it displays 1 submenu and 1
> link looping
> ?>
> <TD><?  echo "$submenu"; ?></TD>
> <TD><a href="<? echo "$url"; ?> "> <? echo "$element"; ?></a> </TD>
> <?
>
> // this doesn't work
> if ($menutable_id == $menuid) {
>                          ?>
>                          <TD><?  echo "equal $submenu"; ?></TD>
>                          <?
>    // print "both equal";
>    //
>    // $b = $a;
>                       }
>
> ?>
>
> Notes:
> Loop de loop:
> // outer loop   display submenus (when submenu changes display next set
> of elements
> or links from inner loop)   if submenu changes then display next set of
> menu links for
> that submenu
> // inner loop display elements or links for that submenu until sub menu
> changes
>
>
> MySQL and PHP4 latest using Linux OS
>
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail
<[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to