Help with my first recursion menu
Help with my first recursion menu
am 28.10.2009 16:54:59 von talofo talofo
Hello all,=20
Please have a look here:
http://www.nuvemk.com/c_categoria/seccao/1
When we click on "Fitof=E1rmacos", I can display the correspondent =
children!
This is great! And I'm really happy!=20
:)
When we click on Fitof=E1rmacos children - "Herbicidas", I was expecting =
to
have returned Herbicidas childs, without losing the Fitof=E1rmacos menu =
item.
The reason I'm losing him, I suppose, it's due the fact that the URI is =
not
properly generated by the function responsible to parse a menu.
Notice that, on the link posted above:
If you click on fitof=E1rmacos and then click on herbicidas, the =
expected URL
should be:
http://www.nuvemk.com/c_categoria/seccao/1/6/9/
but I'm getting this instead:
http://www.nuvemk.com/c_categoria/seccao/6/9/
If we try to navigate deeply, and inside Herbicidas we click on =
"Herbicidas
A", we are expecting an URL like so:
http://www.nuvemk.com/c_categoria/seccao/1/6/9/27/
But we are getting this instead:
http://www.nuvemk.com/c_categoria/seccao/9/27/
Here is the actual code:
http://pastebin.com/m8ffe9db
I've not yet completely understand the recursion, can I have your help =
in
order to understand how can I recursively build the URI segments?
Thanks a lot in advance,
M=E1rcio
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Help with my first recursion menu
am 28.10.2009 22:22:49 von talofo talofo
> -----Original Message-----
> From: MEM [mailto:talofo@gmail.com]
> Sent: quarta-feira, 28 de Outubro de 2009 15:55
> To: 'php-general@lists.php.net'
> Subject: Help with my first recursion menu
>=20
> Hello all,
>=20
> Please have a look here:
> http://www.nuvemk.com/c_categoria/seccao/1
>=20
>=20
> When we click on "Fitof=E1rmacos", I can display the correspondent
> children! This is great! And I'm really happy!
> :)
>=20
> When we click on Fitof=E1rmacos children - "Herbicidas", I was =
expecting
> to have returned Herbicidas childs, without losing the Fitof=E1rmacos
> menu item.
>=20
> The reason I'm losing him, I suppose, it's due the fact that the URI =
is
> not properly generated by the function responsible to parse a menu.
>=20
> Notice that, on the link posted above:
> If you click on fitof=E1rmacos and then click on herbicidas, the =
expected
> URL should be:
> http://www.nuvemk.com/c_categoria/seccao/1/6/9/
>=20
> but I'm getting this instead:
> http://www.nuvemk.com/c_categoria/seccao/6/9/
>=20
> If we try to navigate deeply, and inside Herbicidas we click on
> "Herbicidas A", we are expecting an URL like so:
> http://www.nuvemk.com/c_categoria/seccao/1/6/9/27/
>=20
> But we are getting this instead:
> http://www.nuvemk.com/c_categoria/seccao/9/27/
>=20
>=20
> Here is the actual code:
> http://pastebin.com/m8ffe9db
>=20
> I've not yet completely understand the recursion, can I have your help
> in order to understand how can I recursively build the URI segments?
>=20
>=20
>=20
> Thanks a lot in advance,
> M=E1rcio
I've been told that stack is the way to go, so I'm trying to understand =
the
following code:
http://pastebin.com/m5616c88f
I've commented every line so that any of you could see if I'm =
interpreting
something wrong:
I have two questions about this code, that hopefully someone on the list
could explain:
1)
Why do we need to remove the last array item? (on line 32):
array_pop($urlStack);
2)=20
Why we print the closed tag of the li element, after the recursive call? =
(on
line 29)
echo "\n";
Thanks a lot in advance,
M=E1rcio
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: RE: Help with my first recursion menu
am 31.10.2009 15:04:55 von Lex Braun
--0016e64611423686be04773ba2b9
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Hi,
On Wed, Oct 28, 2009 at 5:22 PM, MEM wrote:
> I've been told that stack is the way to go, so I'm trying to understand
> the
> following code:
> http://pastebin.com/m5616c88f
> I've commented every line so that any of you could see if I'm interpretin=
g
> something wrong:
>
>
> I have two questions about this code, that hopefully someone on the list
> could explain:
>
> 1)
> Why do we need to remove the last array item? (on line 32):
> array_pop($urlStack);
>
On line 20, $url creates an URL path that includes the $cat path. Once
you've completed iteration on all children of $cat, the url path should no
longer include $cat path, thus it is removed from $urlStack.
>
> 2)
> Why we print the closed tag of the li element, after the recursive call?
> (on
> line 29)
> echo "\n";
>
Line 29 is closing the li element that was opened on line 23 for $cat.
>
>
> Thanks a lot in advance,
> Márcio
>
-Lex
--0016e64611423686be04773ba2b9--
RE: RE: Help with my first recursion menu
am 31.10.2009 17:07:40 von talofo talofo
------=_NextPart_000_0013_01CA5A44.472BA8C0
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
=20
From: Lex Braun [mailto:lex.braun@gmail.com]=20
Sent: sábado, 31 de Outubro de 2009 14:05
To: MEM
Cc: php-general@lists.php.net
Subject: Re: [PHP] RE: Help with my first recursion menu
=20
Hi,
On Wed, Oct 28, 2009 at 5:22 PM, MEM wrote:
I've been told that stack is the way to go, so I'm trying to understand =
the
following code:
http://pastebin.com/m5616c88f
I've commented every line so that any of you could see if I'm =
interpreting
something wrong:
I have two questions about this code, that hopefully someone on the list
could explain:
1)
Why do we need to remove the last array item? (on line 32):
array_pop($urlStack);
On line 20, $url creates an URL path that includes the $cat path. Once =
you've completed iteration on all children of $cat, the url path should =
no longer include $cat path, thus it is removed from $urlStack.
=20
2)
Why we print the closed tag of the li element, after the recursive call? =
(on
line 29)
echo "\n";
Line 29 is closing the li element that was opened on line 23 for $cat.
Thanks a lot in advance,
Márcio
-Lex
=20
=20
=20
=20
Thanks a lot. I knew that:
â=9CLine 29 is closing the li element that was opened on line 23 =
for $cat.â=9D
=20
My question intend to be more like:
Why that line to close the li element is *after* the recursive call?=20
Somehow, it seems that instead of creating something like this:
=20
We are doing:
=20
Anyway, the main doubt was the first. I will test this and see what I =
get.=20
=20
Thanks a lot for your reply.
Regards,
Márcio
=20
------=_NextPart_000_0013_01CA5A44.472BA8C0--
Re: RE: Help with my first recursion menu
am 02.11.2009 03:58:24 von Lex Braun
--00151774155a3ef8ee04775a8e52
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Hi,
On Sat, Oct 31, 2009 at 11:07 AM, MEM wrote:
>
>
> *From:* Lex Braun [mailto:lex.braun@gmail.com]
> *Sent:* sábado, 31 de Outubro de 2009 14:05
> *To:* MEM
> *Cc:* php-general@lists.php.net
> *Subject:* Re: [PHP] RE: Help with my first recursion menu
>
>
>
> Hi,
>
> On Wed, Oct 28, 2009 at 5:22 PM, MEM wrote:
>
> I've been told that stack is the way to go, so I'm trying to understand t=
he
> following code:
> http://pastebin.com/m5616c88f
> I've commented every line so that any of you could see if I'm interpretin=
g
> something wrong:
>
>
> I have two questions about this code, that hopefully someone on the list
> could explain:
>
> 1)
> Why do we need to remove the last array item? (on line 32):
> array_pop($urlStack);
>
> On line 20, $url creates an URL path that includes the $cat path. Once
> you've completed iteration on all children of $cat, the url path should n=
o
> longer include $cat path, thus it is removed from $urlStack.
>
>
>
>
> 2)
> Why we print the closed tag of the li element, after the recursive call?
> (on
> line 29)
> echo "\n";
>
> Line 29 is closing the li element that was opened on line 23 for $cat.
>
>
>
> Thanks a lot in advance,
> Márcio
>
> -Lex
>
>
>
>
>
>
>
>
>
> Thanks a lot. I knew that:
>
> â=9CLine 29 is closing the li element that was opened on line 23 for=
$cat.â=9D
>
>
>
> My question intend to be more like:
>
> Why that line to close the li element is **after** the recursive call?
>
> Somehow, it seems that instead of creating something like this:
>
>
>
> - item1
>
> - item2
>
> - item3
>
>
>
>
>
> We are doing:
>
>
>
> - item1
>
> - item2
>
> - item3
>
>
>
>
>
>
>
Say you have a tree menu that contains :
$arr =3D array('item1' =3D> 'Item 1', 'item2' =3D> array('item2a' =3D> 'Ite=
m 2a',
'item2b' =3D> 'Item 2b'));
$urlStack =3D array('category');
When you call the tree() function with the above $arr values, the function
acts as follows:
1. First time through the function, the opening ul element is printed
2. First time through the foreach loop sets $cat =3D 'item1' and $val =3D '=
Item
1'.
3. As this is not an array, the else condition prints Item 1
4. Second time through the foreach loop sets $cat =3D 'Item 2' and $val =3D
array('item2a' =3D> 'Item 2a', 'item2b' =3D> 'Item 2b').
5. As this is an array, the if condition prints a=
nd
calls the tree function recursively
6. Second time through the tree function, another element is printed
and the two sub items are printed as - sub item
as they do not
contain additional arrays. Tree function ends by printing the closing
>
tag.
7. The foreach loop from step 5 continues and prints the closing . Tre=
e
function ends by printing the closing tag.
The output from calling tree($arr, $urlStack) would thus be:
--00151774155a3ef8ee04775a8e52--
RE: RE: Help with my first recursion menu
am 02.11.2009 10:37:20 von talofo talofo
------=_NextPart_000_001B_01CA5BA0.13DB6200
Content-Type: text/plain;
charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
=20
From: Lex Braun [mailto:lex.braun@gmail.com]=20
Sent: segunda-feira, 2 de Novembro de 2009 02:58
To: MEM
Cc: php-general@lists.php.net
Subject: Re: [PHP] RE: Help with my first recursion menu
=20
Hi,
On Sat, Oct 31, 2009 at 11:07 AM, MEM wrote:
=20
From: Lex Braun [mailto:lex.braun@gmail.com]=20
Sent: sábado, 31 de Outubro de 2009 14:05
To: MEM
Cc: php-general@lists.php.net
Subject: Re: [PHP] RE: Help with my first recursion menu
=20
Hi,
On Wed, Oct 28, 2009 at 5:22 PM, MEM wrote:
I've been told that stack is the way to go, so I'm trying to understand =
the
following code:
http://pastebin.com/m5616c88f
I've commented every line so that any of you could see if I'm =
interpreting
something wrong:
I have two questions about this code, that hopefully someone on the list
could explain:
1)
Why do we need to remove the last array item? (on line 32):
array_pop($urlStack);
On line 20, $url creates an URL path that includes the $cat path. Once =
you've completed iteration on all children of $cat, the url path should =
no longer include $cat path, thus it is removed from $urlStack.
=20
2)
Why we print the closed tag of the li element, after the recursive call? =
(on
line 29)
echo "\n";
Line 29 is closing the li element that was opened on line 23 for $cat.
Thanks a lot in advance,
Márcio
-Lex
=20
=20
=20
=20
Thanks a lot. I knew that:
â=9CLine 29 is closing the li element that was opened on line 23 =
for $cat.â=9D
=20
My question intend to be more like:
Why that line to close the li element is *after* the recursive call?=20
Somehow, it seems that instead of creating something like this:
=20
We are doing:
=20
Say you have a tree menu that contains :
$arr =3D array('item1' =3D> 'Item 1', 'item2' =3D> array('item2a' =3D> =
'Item 2a', 'item2b' =3D> 'Item 2b'));
$urlStack =3D array('category');
When you call the tree() function with the above $arr values, the =
function acts as follows:
1. First time through the function, the opening ul element is printed
2. First time through the foreach loop sets $cat =3D 'item1' and $val =
=3D 'Item 1'.=20
3. As this is not an array, the else condition prints Item 1
4. Second time through the foreach loop sets $cat =3D 'Item 2' and $val =
=3D array('item2a' =3D> 'Item 2a', 'item2b' =3D> 'Item 2b'). =20
5. As this is an array, the if condition prints
href=3D''>Item and calls the tree function recursively
6. Second time through the tree function, another element is =
printed and the two sub items are printed as - sub item
as they =
do not contain additional arrays. Tree function ends by printing the =
closing
tag.
7. The foreach loop from step 5 continues and prints the closing . =
Tree function ends by printing the closing tag.
The output from calling tree($arr, $urlStack) would thus be:
=20
=20
=20
Perfectly clear. Thanks a lot Lex. :)
------=_NextPart_000_001B_01CA5BA0.13DB6200--