Re: [PHP] Nested Menu Help
From: [EMAIL PROTECTED] When I am in page A (or one of it's children) I wish to show it's one level of children like so: Page A Child 1 Child 2 etc... Page B When I am in page B (or one of it's children) I wish to show it's one level of children like so: Page A Page B Child 1 Child 2 etc... Do you get the picture? I have a db with link url, id, parent id and title does any one know of a simple function or something to do this for one level? I wrote the code below for a menu system like this on a recent project: -- // declare class (s)elect (l)ist class sl { var $query; var $result; var $row; function set_query($new_value) { $this-query = $new_value; } } // create object (c)ategory (s)elect (l)ist $csl = new sl(); // create object (s)ubcategory (s)elect (l)ist $ssl = new sl(); // set query for object csl to display main categories $csl-set_query(SELECT ID, Name FROM Categories WHERE ParentID=0); $csl-result = mysql_query($csl-query); // display the menu while ($csl-row = mysql_fetch_array($csl-result)) { $ParentCatID=$csl-row[ID]; if ($csl-row[ID] == $MainCatID) { echo(p class=\menuselected\ . a href=$PHP_SELF?MainCatID=$ParentCatID . $csl-row[Name] . /a/p\n); // set query for object (s)ubcategory (s)elect (l)ist $ssl-set_query(SELECT ID, Name, ParentID FROM Categories . WHERE ParentID=$MainCatID); $ssl-result = mysql_query($ssl-query); // display subcategories (submenu) while ($ssl-row = mysql_fetch_array($ssl-result)) { $ParentCatID = $ssl-row[ParentID]; $ChildCatID = $ssl-row[ID]; if ($ssl-row[ID] == $SubCatID) { echo(p class=\submenuselected\ . a href=$PHP_SELF?MainCatID= . $ParentCatIDSubCatID=$ChildCatID . $ssl-row[Name] . /a/p\n); } else { echo(p class=\submenu\ . a href=$PHP_SELF?MainCatID= . $ParentCatIDSubCatID=$ChildCatID . $ssl-row[Name] . /a/p\n); } } } // finish main category display else { echo(p class=\menu\ . a href=$PHP_SELF?MainCatID=$ParentCatID . $csl-row[Name] . /a/p\n); } } -- Main menu categories have a ParentID assignment of 0 in the db. A select is done of all ID Name in the Categories table where ParentID=0. The menu is displayed with names linked to recalling the script and passing the variable $MainCatID -- the ID of the category. When the script is called with $MainCatID set (when a main menu category is selected), the menu name with ID matching $MainCatID is assigned a style class to distinguish visually that it's selected. Also at this point another selection is done from Categories where ParentID=$MainCatID, thus creating the list of subcategories for the selected main category. The subcategories are also displayed with links back to the script passing the variable $MainCatID again plus the variable $SubCatID. When the script is called with $SubCatID set, the submenu name with ID equal to $SubCatID is also class-styled to indicate the selection. The main page display (in this case for a products catalog) is generated by other selection queries based on $MainCatID and $SubCatID. -- Lowell Allen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Nested Menu Help
When I am in page A (or one of it's children) I wish to show it's one level of children like so: Page A Child 1 Child 2 etc... Page B When I am in page B (or one of it's children) I wish to show it's one level of children like so: Page A Page B Child 1 Child 2 etc... Do you get the picture? I have a db with link url, id, parent id and title does any one know of a simple function or something to do this for one level? I have tried and sort of failed 3 times. And before I keep trying I thought I would ask this group JJ Harrison[EMAIL PROTECTED]www.tececo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Nested Menu Help
I found a way of doing this in order to show the home button when browsing the site, but not when seeing the home page. What I do, is to set two menus like this: If ($browse == yes) { a href=index.phphome/a } a href=page1.php?browse=yespage 1/a a href=page2.php?browse=yes page 2/a a href=page3.php?browse=yes page 3/a Notice how the links to other pages have the browse=yes set. You could do something like this by building two menus (A and B) so PHP will read something like browse=a or browse=b and fetch the right buttons from the DB using different queries. I know there must be an easier way, but so far, this is what I came with which suites my needs very well. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Friday, June 21, 2002 6:13 AM To: [EMAIL PROTECTED] Subject: [PHP] Nested Menu Help When I am in page A (or one of it's children) I wish to show it's one level of children like so: Page A Child 1 Child 2 etc... Page B When I am in page B (or one of it's children) I wish to show it's one level of children like so: Page A Page B Child 1 Child 2 etc... Do you get the picture? I have a db with link url, id, parent id and title does any one know of a simple function or something to do this for one level? I have tried and sort of failed 3 times. And before I keep trying I thought I would ask this group JJ Harrison [EMAIL PROTECTED] www.tececo.com
Re: [PHP] Nested Menu Help
On Friday 21 June 2002 17:12, [EMAIL PROTECTED] wrote: When I am in page A (or one of it's children) I wish to show it's one level of children like so: Page A Child 1 Child 2 etc... Page B When I am in page B (or one of it's children) I wish to show it's one level of children like so: Page A Page B Child 1 Child 2 etc... Do you get the picture? I have a db with link url, id, parent id and title does any one know of a simple function or something to do this for one level? Have a look here: http://phpclasses.gremlins.com.hk There are a number of classes which deals with these tree menus. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* I do not fear computers. I fear the lack of them. -- Isaac Asimov */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php