You are here: Re: Recursive menu « PHP Programming Language « IT news, forums, messages
Re: Recursive menu

Posted by larry on 12/09/07 04:00

On Dec 8, 6:50 pm, Kim G <kim...@gmail.com> wrote:
> Hi.
>
> I am having some trouble with a recursive function that displays a
> menu. In my database I have two fields that matters: page_id and
> parent_id. Displaying the menu correctly is not a problem, but I need
> it to expand the subpages of a parent page only when the user is
> reading the parent page of a set of subpages, or one of the subpages,
> or one of the subpages' subpage etc.. When the user is reading the
> frontpage, only the pages with parent_id = 0 should be displayed.
>
> Does anyone have a reasonable solution to this problem?

This is code from my site, I don't go into subpages on my page menus,
but my sitelist does, I specify the root page at the beginning and in
goes through the menu tree.

It should work the way you want by just specifying your page ID.

here's how it looks on my site:
http://www.portcommodore.com/sitemap.php

hope thats useful
Larry

database table, url:

CREATE TABLE `url` (
`url_id` varchar(9) NOT NULL default '',
`url_name` varchar(40) NOT NULL default '',
`url_location` varchar(60) NOT NULL default '',
`url_description` varchar(255) NOT NULL default '',
`url_parents` varchar(50) NOT NULL default '',
`url_path` varchar(80) NOT NULL default '',
PRIMARY KEY (`url_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

id - is a text based id (i.e. photos')
name - a text name (what shows on the menu
location - the file name of the PHP page
description - a description of the page
parents - in my site pages can have multiple parents, which the text
IDs are csv in the field
path - default menu path for the entry (i.e. main-cbmidx-bbsidx ),
this gives a default trackback of menus to the main menu. (if someone
calls it direct, otherwise I have GET provide a trackback.)

Te root menu ID (url_id) is "main", so I call to generate the site
map:

ulist('main');


function ulist($iname) {
$record = dbquery(
"SELECT *
FROM url
WHERE url_id='".$iname."' LIMIT 1");
$item = mysql_fetch_array($record);
echo "
<ul>
<li>
<b><a href=\"".$item['url_location']."\">".
$item['url_name']."</a></b>";
echo "<br />
".$item['url_description']."</li>
";
$match = dbquery(
"SELECT *
FROM url
WHERE
url_parents LIKE '%".$item['url_id']."%'
AND url_id != 'main'
ORDER BY url_name");
if( mysql_num_rows($match) > 0){
while( $list = mysql_fetch_array($match) ){
ulist($list['url_id']);
}
}
echo "</ul>";
}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация