Forum Moderators: coopster

Message Too Old, No Replies

Optimizing Loops

Categories and Subcategories

         

inveni0

2:54 pm on Apr 6, 2009 (gmt 0)

10+ Year Member



Okay, so I need to select a list of categories from mySql. It is arranged like this:


catid catname catparent
1 first 0
2 second 0
3 firstsub 1
4 secondsub 2

The only way I know to do this is loop through every category, starting with the parent category, finding all of the children categories and building a sort of hierarchy from it. I know that it's common to need to do this sort of thing, so I was wondering if there were a better way--perhaps some way of optimizing the code to be nice and fast?

inveni0

1:23 pm on Apr 7, 2009 (gmt 0)

10+ Year Member



Any ideas on this, or is my thinking probably as good a way as any?

trillianjedi

2:53 pm on Apr 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you read this:-

[dev.mysql.com...]

inveni0

3:03 pm on Apr 7, 2009 (gmt 0)

10+ Year Member



No, I haven't! Thanks!