Link to home
Start Free TrialLog in
Avatar of AHMED SAMY
AHMED SAMYFlag for Egypt

asked on

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.
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

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.
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AHMED SAMY

ASKER

i need to loop all category name and its parent name to load all categories and its sub categories like windows explorer
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

<select>
              <optgroup>
                            <option></option>
             </optgroup>
            <option></option>
</select>

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

Dynamic Category Subcategory Tree using PHP and MySQL
any suggestion else ??
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?
no i trust your solution
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?
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.
Can I ask this - what do you want it to do that the Example you should us does not already do?
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.

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