for professionals only

i have normal case need logic and deep thinking in vb.net there is Recursive Loop
you can know about it from this link for example:Recursive Loop

i have categories and sub categories table need to bring them like that:

category----
       subcategory
      subcategory
category----
       subcategory
      subcategory

i have this table i need to understand not only the code.
AHMED SAMYownerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
For clarification, your question is mentioning vb.net but your question topic is php.  Are you looking for a php or vb.net solution?

The easiest way to solve a problem like this is to start at the end result.  What is it you are trying to achieve? What does the end result look like?  In explaining this, it may be easier to just let us know exactly what you are working on.
0
Julian HansenCommented:
I see from your data that you have a setup where your database records are hierarchical each record has a parent to say what category it belongs to.

What I am not sure is - what your question is.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AHMED SAMYownerAuthor Commented:
i need to loop all category name and its parent name to load all categories and its sub categories like windows explorer
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Julian HansenCommented:
Getting the data is easy SELECT * FROM tablename

However, what you do with it after that is highly dependent on the use case - are you wanting a solution that will output the categories in a tree - if so how do you want to represent the tree?
As a nested HTML <ul>?
<ul>
    <li>
            <ul> ...</ul>
     </li>
</ul>

Open in new window

0
AHMED SAMYownerAuthor Commented:
<select>
              <optgroup>
                            <option></option>
             </optgroup>
            <option></option>
</select>

that how i need but don't know how many levels user will use
0
AHMED SAMYownerAuthor Commented:
thanks all of you very much i found this example is very good for me

Dynamic Category Subcategory Tree using PHP and MySQL
0
AHMED SAMYownerAuthor Commented:
any suggestion else ??
0
Julian HansenCommented:
I don't like that solution because it iteratively calls the database which is not necessary - you can solve the problem getting the data once.

Are you wanting a <select> solution as they have it there?
0
AHMED SAMYownerAuthor Commented:
no i trust your solution
0
Julian HansenCommented:
I think we are at cross purposes - I cannot answer the question unless I know what you are expecting to see on the screen - are you wanting to see it as in the example you showed me or do you want to use it in a different way?
0
AHMED SAMYownerAuthor Commented:
i will show it to user as a select menu  to choose categories when adding a new subcategory on categories screen

and i will make it show only last subcategory which we can add products  on products screen when he adding a new

product and choose category.
0
Julian HansenCommented:
Can I ask this - what do you want it to do that the Example you should us does not already do?
0
AHMED SAMYownerAuthor Commented:
i have store i make a page add products and choose categories for this products and need to let user choose only last root which is not parent

and i need to know your opinion about bset way



I don't like that solution because it iteratively calls the database which is not necessary - you can solve the problem getting the data once.

0
AHMED SAMYownerAuthor Commented:
sorry for being late
0
Julian HansenCommented:
and i need to know your opinion about bset way
I can't answer that - I don't know enough about your system.

My advice is implement as per the sample and see how far that gets you - after you have used it for a bit it will be clear whether it works for you or not.
0
AHMED SAMYownerAuthor Commented:
mmmmm!

right now it did what i want but this recursive loop is new idea for me i need your experience about it's problems

if you have best way not bset way
0
AHMED SAMYownerAuthor Commented:
thanks
0
Julian HansenCommented:
Recursion is very common in Computer Science problems - but sometimes it is not implemented correctly. Whenever you have a situation where you are dealing with hierarchical data then recursion is the usual solution that is applied.

If you have a two level hierarchy then you can simplify it a bit by ensuring your data is sorted on parent and then keeping track of the parent name. When it changes you end the tree and start a new one for the next parent.

However, this is not much different from the recursive approach so if you have a recursive process that works for you I would stick to it.
0
AHMED SAMYownerAuthor Commented:
thanks i will be back may be for this
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.