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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.
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.

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
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

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

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
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
AHMED SAMYownerAuthor Commented:
any suggestion else ??
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?
AHMED SAMYownerAuthor Commented:
no i trust your solution
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?
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.
Julian HansenCommented:
Can I ask this - what do you want it to do that the Example you should us does not already do?
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.

AHMED SAMYownerAuthor Commented:
sorry for being late
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.
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
AHMED SAMYownerAuthor Commented:
thanks
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.
AHMED SAMYownerAuthor Commented:
thanks i will be back may be for this
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.