I have an application that needs to be able to get procedures from a database and display the steps in the correct order. Sometimes, steps have substeps, and other times, those substeps can have substeps of their own. It's not an option for me to write a separate html page for each procedure, since we're talking about quite a lot of them. I intend to generate the view on the fly. Here is a sample of what I would be displaying:
1. Step 1
a. Step 1a
i. Step 1ai
ii. Step 1aii
b. Step 1b
2. Step 2
As it currently stands, I have a PROCEDURE table, a STEP table, and a PROCEDURE_STEP table to cross reference them. The STEP table has a substep_of field, which is a foreign key to the id of the parent step. I'm still at the stage where I can modify the database as needed.
My question then, is after I do this:
mysql_query(SELECT * FROM PROCEDURE_STEP WHERE procedure_id = $id);
How do I sort them so that each substep is neatly placed in the return array in order under its parent step? I'm going to send the return array to the view as a json encoded array, if that makes a difference.