RE: [PHP] array recursion from database rows
Bob, Post your failing code and we'l be glad to give you pointers on fixing it. This list doesn't exist to write code for you (unless your dropping coin into our paypal account) but all of us are willing to help with posted code. Wolf -Original Message- From: Bob <[EMAIL PROTECTED]> Sent: Saturday, May 24, 2008 2:25 PM To: php-general@lists.php.net Subject: [PHP] array recursion from database rows Hi. I have a database table I have created for navigation. The table fields are uid, parent_id, menu_name. Each entry is either a top level element with a parent_id of 0 or a child which has a parent_id that relates to the parent uid. What I am trying to do is recurse through a set of rows adding the child(ren) of a parent to a multi-dimensional array. Does anyone know how I can do this, I've tried (unsuccessfully) to traverse the rows to create this array but I keep failing miserably. This is probably very easy for the people on this list so I am hoping someone could help me out. Thanks in advance. Cheers. Bob -- [The entire original message is not included] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array recursion from database rows
On 5/24/08, Bob <[EMAIL PROTECTED]> wrote: > > Hi. > > I have a database table I have created for navigation. > > The table fields are uid, parent_id, menu_name. > > Each entry is either a top level element with a parent_id of 0 or a child > which has a parent_id that relates to the parent uid. > > What I am trying to do is recurse through a set of rows adding the > child(ren) of a parent to a multi-dimensional array. > > Does anyone know how I can do this, I've tried (unsuccessfully) to traverse > the rows to create this array but I keep failing miserably. > > This is probably very easy for the people on this list so I am hoping > someone could help me out. > > Thanks in advance. > > Cheers. > > Bob if you order your result set by record id and parent id then your set should be much easier to loop thru, when you hit an empty parent id field its a new parent and you could use the row id (or whaever) as the key and then keep adding the children until you hit a new (empty) parent id -- > > Bastien > > Cat, the other other white meat
[PHP] array recursion from database rows
Hi. I have a database table I have created for navigation. The table fields are uid, parent_id, menu_name. Each entry is either a top level element with a parent_id of 0 or a child which has a parent_id that relates to the parent uid. What I am trying to do is recurse through a set of rows adding the child(ren) of a parent to a multi-dimensional array. Does anyone know how I can do this, I've tried (unsuccessfully) to traverse the rows to create this array but I keep failing miserably. This is probably very easy for the people on this list so I am hoping someone could help me out. Thanks in advance. Cheers. Bob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php