ok, if Im understanding this right, you want to have categories, with multiple sub 
categories, you want to have links inside any category (inc sub-categories) right? 
well I use three tables.

link
- link_id
- link_name
- link_url
link_cat
- link_id
- link_cat
cat
- cat_id
- cat_name
- cat_parent

I use two tables for links for a reason, I wanted to be able to have a link in 
multiple categories, this is the simplest method. I'll put some values in the tables 
so you can get an idea how it works.

link
001    mediawave    www.mediawaveonline.com
002    slashdot        www.slashdot.org
003    google            www.google.com
004    yahoo            www.yahoo.com

link_cat
001    001
002    002
003    003
004    003

cat
001    category1    000
002    category2    001
003    category3    001
004    category4    002
005    category5    003

there we go, we some data to play with.

now to make a pretty category tree we use recursion. everyone say 'oi' together now.

class cat
{

 function make_tree($cat_id = 0)
 {
  static $padding = 0;
  
  $padding++;
  foreach($database->select_array('', 'cat', "WHERE cat_id = $cat_id") as $pos => 
$result)
  {
   $cat_id = $result['cat_id'];
   
   $this->cat_id[$cat_id]   = $result['cat_id'];
   $this->cat_name[$cat_id]  = $result['cat_name'];
   $this->cat_parent[$cat_id] = $result['cat_parent'];
   $this->cat_space[$cat_id]  = $padding;
   
   make_tree($cat_id);
  }
  $padding--;
 }
}

(I havent checked this code, its just an example)

to get the links, not a problem either.

class link
{

 function get_links($cat = '')
 {
  if ($cat)
   $query = "WHERE l.link_id = lc.link_id AND lc.link_cat = $cat":
  else
   $query = "WHERE l.link_id = lc.link_id":
   
  foreach($database->select_array('', 'link as l, link_cat as lc', $query) as $pos => 
$result)
  {
   $id  = $result['link_id'];
   $cat = $result['link_cat'];

   $this->link_id[$id]     = $result['link_id'];
   $this->link_cat[$id][$cat] = $result['link_cat'];
   $this->link_url[$id]    = $result['link_url'];
   $this->link_name[$id]    = $result['link_name'];
  }
 }
}

ok this is a supper basic example, but try it, modify it, play around. it'll give you 
a basic idea.


-- 

 Chris Lee
 [EMAIL PROTECTED]




"Fates" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
I am trying to make a simple HTML menu system. I am having problems
displaying
menu links under the correct submenu from a loop.  I want to be able to
change web menus on the fly.

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:
// 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


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to