I’m building a form with php/mysql. I’ve got a table with a list of locations and sublocations. Each sublocation has a parent location. A column ‘parentid’ references another locationid in the same table. I now want to load these values into a dropdown in the following manner:
--Location 1 ----Sublocation 1 ----Sublocation 2 ----Sublocation 3 --Location 2 ----Sublocation 4 ----Sublocation 5
etc. etc.
Did anyone get an elegant solution for doing this?
NOTE: This is only psuedo-code.. I didn’t try running it, though you should be able to adjust the concepts to what you need.
With BaileyP’s valid criticism in mind, here’s how to do it WITHOUT the overhead of calling multiple queries in every loop: