Thanks for that info.
I am still a bit new to programming/PHP to fully grasp that but I am sure I
will in time.
*anyway*
when I echo menu($id) I get the current page's title.
How do I print it's peers and it's single parent?
--
JJ Harrison
[EMAIL PROTECTED]
www.tececo.com
P.S. I originally wanted to build a hierachy based menu like this but failed
Page 3
Page 4
P4 C1
P4 C2(I am here)
etc...
I went fine until I have to print the parent and it's peers like shown in
the example
P.P.S if you had a couple of functions which would help me do this I would
be grateful, but don't write anything.
P.P.P.S. All pages have information provided by this script:
$fn = explode("/", $_SERVER['PHP_SELF']);
$num_of_s = count($fn) - 1;
$fn = "$fn[$num_of_s]";
$query = "SELECT * FROM meta_data WHERE page_name = '$fn'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
$row = mysql_fetch_array($result);
$id = $row['id'];
$pid = $row['pid'];
$title = $row['title'];
$description = $row['description'];
$keywords = $row['keywords'];
It is my metadata page and is used all over the place. so why re-query the
db for it's parent?
"Richard Lynch" <[EMAIL PROTECTED]> wrote in message
news:20020701232031.VNMV6023.sccrmhc02.attbi.com@[192.168.1.103]...
> >I have a table with id, pid(parent), title and page_name(url) fields.
> >
> >The vars provided to the script are the current page's title, id and
> >pid(parent)
>
> You can look up the parent and in the database, so it's not horribly
> important that those be provided.
>
> *UNLESS* you have a heterarchy, and not a hierarchy -- In other words,
> *UNLESS* there are two different "paths" to get to 'id' through different
> parents. In other other words, *UNLESS* you have duplicate id's in the
> database... If you *DO* have a heterarchy, you'd need to track the user's
> path as they traveled to know which route to display.
>
> I'll assume you don't have a heterarchy, for now.
>
> >When I am on the parent page I get this(Which is what I want):
> >[ Chronological History ][ Website Chronological History ]
> >
> >When I am in the Child I get this:
> >
> >[ Website Chronological History ][ Website Chronological History ]
> >
> >What am I doing wrong???
>
> You really can't get all the parents in one SQL statement.
>
> You'll need to look up the parent. Then the grand-parent. Then the
> great-grand-parent. And so on.
>
> Each with a different SQL query.
>
> Now, this is not ideal for performance.
>
> In fact, it's *HORRIBLE* if (A) your tree is really "deep" -- If you have
10
> generations of "depth" to the ggggg'great-grand-parents, then it's gonna
> take 9 queries to look it up.
>
> If you're only looking at three or four levels, it's really no big deal...
> Unless your site is, like, getting a zillion hits.
>
> Let's assume it's not getting a zillion hits for now, okay?
>
> >I have stared at this two many times now and am probably missing the
obvious
> >
> >function menu($id, $pid, $title) {
> > $query = "select * from meta_data WHERE pid = '$id' OR pid = '$pid'
&&
> >pid != 0";
>
> This will give both the current record and the parent record, but never,
> ever, ever, the grand-parent record...
>
> > $result = mysql_query($query);
> > $num_results = mysql_num_rows($result);
> > if($num_results != 0){
> > ?>
> ><table width="100%">
> ><tr><td align="center">
> > <?
> > echo '[ '.$title.' ]';
> > for ($i=0; $i < $num_results; $i++)
> > {
> > $row = mysql_fetch_array($result);
> > if($id == $row['id']){
> > echo '[ '.$row['title'].' ]';
> > } elseif($row['pid'] == $id || $row['id'] == $pid && $pid != 0) {
> > echo '[ <a
> >href="'.$row['page_name'].'">'.$row['title'].'</a> ]';
> > }
> > }
> > ?>
> ></td></tr>
> ></table>
> > <?
> > }
>
> Try something more like this:
>
> function menu($id){
> $query = "select pid, title from meta_data where id = $id";
> $meta = mysql_query($query) or error_log(mysql_error()); # Check HTTP
> error_log for SQL errors!
> list($pid, $title) = mysql_fetch_row($meta, 0);
> if (isset($pid) && $pid)){
> # Switch the menu() and $title parts around if you want bread-crumbs
in
> the other direction
> $result = menu($pid) . $title;
> }
> else{
> $result = '';
> }
> return $result;
> }
>
> NOTE:
>
> There *ARE* techniques for encoding the SQL in such a way that a single
SQL
> statement can get the entire "path" at once, but they get kinda
complicated
> and gnarly, and, really, as I said, if you have a shallow tree, it's just
> not worth the hassle... If you have a really *DEEP* tree, you'll need to
do
> some more research.
>
> --
> Like Music? http://l-i-e.com/artists.htm
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php