Question
Question About Looping Over A List
In my application I have a table that stores information about products. One column in that table, called "options", stores a list of numbers like "1,3,2,4". In some cases the numbers may not be in numerical order, for which I have reasons. Each of these numbers represents the indexed row from another table, "sizes", where I store a list of the sizes and information about each.
On the page displaying a product to visitors I pull data from the "options" field and loop over it. Inside the loop I retrieve the corresponding row from the "sizes" table, and it is added as an order option in a pull-down menu. For example, "1,3,2,4" is:
(1) Small
(3) Large
(2) Medium
(4) X-Large
I want to be able to order the results alphabetically, rather than numerically or the order they are in my "options" column, like:
(3) Large
(2) Medium
(1) Small
(4) X-Large
Is there any easy way to reorder these? I thought of having my application re-order them when they are initially set up, but in some cases the names of each size may change after being set. Clearly having it re-order them on output is the best solution.