Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8019609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:26:17+00:00 2026-06-04T21:26:17+00:00

I have an application that needs to be able to get procedures from a

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:26:21+00:00Added an answer on June 4, 2026 at 9:26 pm

    You would probably want to do something like:

    SELECT s.id, s.substep_of AS parent
    FROM STEP s, PROCEDURE_STEP ps
    WHERE ps.step_id = s.id
    AND ps.procedure_id = $id;
    

    This would get you a list of steps, each containing an id and a parent id. From this, you can build a tree recursively :)…

    function get_children_of( $id, $steps ) {
        $children = array();
    
        foreach( $steps as $step )
            if( $step->parent == $id ) 
                $children[$step->id] = get_children_of( $step->id, $steps );
    
        // Make it null... so we don't have deal with empty arrays
        if( empty( $children ) ) $children = null; 
    
        return $children;            
    }
    
    $steps = run_crazy_mysql_query();
    $tree = get_children_of( 0, $steps );
    

    This should give you a tree that looks like:

    0 => array(
        1 => null,
        2 => array(
            3 => null,
            4 => null
        )
    )
    

    That should give you something you can work with relatively easily to generate HTML lists of steps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that needs to check a website feed every second. Sometimes
imagine a situation where you have an application that needs to import data from
I have a Silverlight application that needs to get the label of an OptionSetValue
I have a Flex application that needs to be able to validate hundreds of
I have an application that needs to work with a vendor-supplied API to do
I have an application that needs to highlight individual pixels on an image. I
I have an application that needs to determine whether a user has made a
I have an application that needs branding when downloaded in certain continents. When installed
I have an application that needs to operate on Windows 2000. I'd also like
I have a server application that needs to find and exchange small amounts of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.