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

  • SEARCH
  • Home
  • 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 6643989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:06:54+00:00 2026-05-26T00:06:54+00:00

I have a php page pulling data from a sql2000 stored procedure representing the

  • 0

I have a php page pulling data from a sql2000 stored procedure representing the BOM (Bill of Material) for a product. Right now it’s displaying as a flat table, and works great. However, after 3 days of googling/hacking, I can’t for the life of me figure out how tranform that data into an indented collapsable/expandable table or UL.

Table is as follows:

  • ID[<–unique]
  • BOM_Level
  • Parent_Item
  • Component_Item
  • Component_qty

The BOM_Level is exactly that, the level of the BOM (a number between 0-12). I was assuming because that was provided it would be simple, in that the bom_level really represents the level of indentation of each part, but alas, it has not been simple….

The general structure is as follows, but the number of parts and levels will vary by product:

0 Top Level
 1 - Assembly 1
  2 - part 1 of Assembly 1
  2 - part 2 of Assembly 1
  2 - part 3 of Assembly 1
  2 - part 4 of Assembly 1
 1 - Assembly 2
  2 - Assembly 1 of Assembly 2
   3 - part 1 of Assembly 1 of Assembly 2
   3 - part 2 of Assembly 1 of Assembly 2
   3 - part 3 of Assembly 1 of Assembly 2

I’ve been trying to do something like:

  • If the bom_level is == previous_bom_level then create li
  • If the bom_level is > previous_bom_level add a new UL and start new li
  • If the BOM level is < previous bom level, wrap up the previous UL and start another set of li.

With all that being said, I just can’t quite wrap my head around how to do this. Any ideas?

  • 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-05-26T00:06:54+00:00Added an answer on May 26, 2026 at 12:06 am

    Suppose you have data like this:

    // plus any additional data per entry
    $data = array (
      array (
        'id' => '10',
        'bom_level' => '2',
        'parent_item_no' => '2800CF',
        'comp_item_no' => '2800CF-02',
      ),
      array (
        'id' => '66',
        'bom_level' => '3',
        'parent_item_no' => '2800CF-02',
        'comp_item_no' => '2000CF-12',
      ),
      array (
        'id' => '189',
        'bom_level' => '4',
        'parent_item_no' => '2000CF-12',
        'comp_item_no' => '0578',
      ),
      array (
        'id' => '190',
        'bom_level' => '4',
        'parent_item_no' => '2000CF-12',
        'comp_item_no' => '2000CF-SH11',
      ),
      array (
        'id' => '222',
        'bom_level' => '5',
        'parent_item_no' => '2000CF-SH11',
        'comp_item_no' => '1000',
      ),
      array (
        'id' => '191',
        'bom_level' => '4',
        'parent_item_no' => '2000CF-12',
        'comp_item_no' => '2000CF-SH12',
      ),
      array (
        'id' => '223',
        'bom_level' => '5',
        'parent_item_no' => '2000CF-SH12',
        'comp_item_no' => '1000',
      ),
      array (
        'id' => '67',
        'bom_level' => '3',
        'parent_item_no' => '2800CF-02',
        'comp_item_no' => '2000CF-AG01',
      ),
      array (
        'id' => '192',
        'bom_level' => '4',
        'parent_item_no' => '2000CF-AG01',
        'comp_item_no' => '303025-20',
      ),
      array (
        'id' => '68',
        'bom_level' => '3',
        'parent_item_no' => '2800CF-02',
        'comp_item_no' => '2000CF-PL13',
      ),
      array (
        'id' => '193',
        'bom_level' => '4',
        'parent_item_no' => '2000CF-PL13',
        'comp_item_no' => '0500',
      ),
      array (
        'id' => '69',
        'bom_level' => '3',
        'parent_item_no' => '2800CF-02',
        'comp_item_no' => '2000CF-PL14',
      ),
      array (
        'id' => '194',
        'bom_level' => '4',
        'parent_item_no' => '2000CF-PL14',
        'comp_item_no' => '0187',
      ),
      array (
        'id' => '70',
        'bom_level' => '3',
        'parent_item_no' => '2800CF-02',
        'comp_item_no' => '2000CF-SQ01',
      ),
      array (
        'id' => '195',
        'bom_level' => '4',
        'parent_item_no' => '2000CF-SQ01',
        'comp_item_no' => '050018-20',
      ),
      array (
        'id' => '71',
        'bom_level' => '3',
        'parent_item_no' => '2800CF-02',
        'comp_item_no' => '2000CF-WB06',
      ),
      array (
        'id' => '196',
        'bom_level' => '4',
        'parent_item_no' => '2000CF-WB06',
        'comp_item_no' => '040013-20',
      ),
    );
    

    Where comp_item_no is unique, and parent_item_no points to it’s parent. With parent_item_no=0 being a root node.

    You can map this to another structure with:

    $map = array();
    foreach ($data as $entry) {
      if (!isset($map[$entry['parent_item_no']])) {
        $map[$entry['parent_item_no']] = array();
      }
    
      $map[$entry['parent_item_no']][] = $entry;
    }
    

    Which in turn can be recursively traversed, with something like this:

    function helper($children, $map) {
      if (sizeof($children) > 0) {
        echo '<ul>';
        foreach ($children as $parentId => $child) {
          echo '<li>';
          echo $child['comp_item_no'];
          if ($child['comp_item_no'] !== $child['parent_item_no'] && isset($map[$child['comp_item_no']])) {
            helper($map[$child['comp_item_no']], $map);
          }
          echo '</li>';
        }
        echo '</ul>';
      }
    }
    
    /**
     * note that '2800CF' here is manually choosen
     * because it has the lowest bom_level! In your real
     * code you might want to capture those nodes while
     * restructuring the array (see above)
     */
    helper($map['2800CF'], $map); 
    

    to produce a nested ul. Example (for the data from above):

    • 2800CF-02
      • 2000CF-12
        • 0578
        • 2000CF-SH11
          • 1000
        • 2000CF-SH12
          • 1000
      • 2000CF-AG01
        • 303025-20
      • 2000CF-PL13
        • 0500
      • 2000CF-PL14
        • 0187
      • 2000CF-SQ01
        • 050018-20
      • 2000CF-WB06
        • 040013-20

    Demo: http://codepad.org/FJwX3Z1c

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

Sidebar

Related Questions

I have a php page that displays rows from a mysql db as a
I have a PHP-generated page which is displaying some data about a set of
I have a particular PHP page that, for various reasons, needs to save ~200
I have a site with URLs like this: http://domain.co.uk/subdir/page.php I have redesigned the site
How do I pass have a Javascript script request a PHP page and pass
I have a web page x.php (in a password protected area of my web
I'd like to have a page in php that normally displays information based on
Let's say I have a page called display.php and the user is viewing display.php?page=3
I have a page that is accessed via a URL like this: http://power-coder.net/Test/something.php?id=3#Page1 I
so im learning php (begginer if you cant tell) and, im currently pushin/pulling data

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.