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 7929679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:10:00+00:00 2026-06-03T20:10:00+00:00

I have been working on this for what seems like forever, so I finally

  • 0

I have been working on this for what seems like forever, so I finally decided to ask for help. I am trying to write an html list that is populated by info in a mysql database. I am trying to write a php loop (or multiple loops) to accomplish this. It begins to get complicated because there a multiple nodes to the list. I have tried many different methods but cannot get the desired results. Any help would be greatly appreciated!

The list is populated by items that have various “categories” and “subcategories”. The list should be in ASC order by customer name, then category, then subcategory, then part number. Some items have only a category and no subcategory. Some items have no category and should just be listed under the customer’s name. So the list should look like this…

Customer1
    – Category1
        – Subcategory1
                – Part1 (Item w/ Category & Subcategory)
                – Part2
        – Subcategory2
                – Part3
    – Category2
        – Part4 (Item with only a Category)
        – Part5
    – Part6 (Item with no Category or Subcategory
    – Part7
Customer2
    – Category1
        – Subcategory1
                – Part1 (Item w/ Category & Subcategory)
                – Part2
        – Subcategory2
                – Part3

Etc……

Hopefully that is clear enough.

Here is my first try with this problem and it comes close. It just places items in the wrong places (not sure why).

    <?php
    $con = mysql_connect("localhost:3306","root","");
    if (!$con)
    {
        die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("pcu_ops", $con);

    $sql_customer="SELECT DISTINCT customer FROM common_parts ORDER BY customer ASC";

    $result_customer=mysql_query($sql_customer,$con);

    if (!mysql_query($sql_customer,$con))
    {
        die('Error: ' . mysql_error());
    }
?>
<table border="0">
    <colgroup>
        <col width="300px" valign="top">
        <col width="90%">
    </colgroup>
    <tr>
        <td valign="top">
            <!-- Add a <div> element where the tree should appear: -->
            <div id="common_parts_tree">
                <ul>
                    <?php
                        while ($row_customer = mysql_fetch_array($result_customer)) {
                            echo '<li class="expanded folder">'.$row_customer['customer'];
                                echo '<ul>';
                                    $customer=$row_customer['customer'];
                                    $sql_category="SELECT DISTINCT category FROM common_parts WHERE customer='$customer' ORDER BY customer ASC";
                                    $result_category=mysql_query($sql_category,$con);
                                    if (!mysql_query($sql_category,$con)) {
                                        die('Error: ' . mysql_error());
                                    }
                                    while ($row_category = mysql_fetch_array($result_category)) {
                                        if ($row_category['category'] != '') {
                                            echo'<li class="expanded folder">'.$row_category['category'];
                                                echo '<ul>';
                                                    $category=$row_category['category'];
                                                    $sql_subcategory="SELECT DISTINCT subcategory FROM common_parts WHERE (customer='$customer' AND category='$category') ORDER BY subcategory ASC";
                                                    $result_subcategory=mysql_query($sql_subcategory,$con);
                                                    if (!mysql_query($sql_subcategory,$con)) {
                                                        die('Error: ' . mysql_error());
                                                    }
                                                    while ($row_subcategory = mysql_fetch_array($result_subcategory)) {
                                                        if ($row_subcategory['subcategory'] != '') {
                                                            echo'<li class="expanded folder">'.$row_subcategory['subcategory'];
                                                                echo '<ul>';
                                                                    $subcategory=$row_subcategory['subcategory'];
                                                                    $sql_pn="SELECT DISTINCT pn FROM common_parts WHERE (customer='$customer' AND category='$category' AND subcategory='$subcategory') ORDER BY pn ASC";
                                                                    $result_pn=mysql_query($sql_pn,$con);
                                                                    if (!mysql_query($sql_pn,$con)) {
                                                                        die('Error: ' . mysql_error());
                                                                    }
                                                                    while ($row_pn = mysql_fetch_array($result_pn)) {
                                                                        $pn=$row_pn['pn'];
                                                                        echo '<li><a href="includes/phpscripts/part_quick_view.php?pn='.$pn.'&customer='.$customer.'" target="contentFrame">'.$pn.'</a>';
                                                                    }
                                                                echo '</ul>';
                                                        }
                                                        else {
                                                            if ($row['subcategory'] == '') {
                                                                $sql_pn="SELECT DISTINCT pn FROM common_parts WHERE (customer='$customer' AND category='$category') ORDER BY pn ASC";
                                                                $result_pn=mysql_query($sql_pn,$con);
                                                                if (!mysql_query($sql_pn,$con)) {
                                                                    die('Error: ' . mysql_error());
                                                                }
                                                                while ($row_pn = mysql_fetch_array($result_pn)) {
                                                                    $pn=$row_pn['pn'];
                                                                echo '<li><a href="includes/phpscripts/part_quick_view.php?pn='.$pn.'&customer='.$customer.'" target="contentFrame">'.$pn.'</a>';
                                                                }
                                                            }
                                                        }
                                                    }
                                                echo '</ul>';
                                        }
                                        else {
                                            echo '<li><a href="includes/phpscripts/part_quick_view.php?pn='.$pn.'&customer='.$customer.'" target="contentFrame">'.$pn.'</a>';
                                        }
                                    }
                                echo '</ul>';
                        }
                    ?>
            </div>
        </td>
        <td>
            <iframe src="" name="contentFrame" width="100%" height="500" scrolling="yes" marginheight="0" marginwidth="0" frameborder="0">
                <p>Your browser does not support iframes</p>
            </iframe>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <center>
                <form id="rcv_common_parts">
                <input type="hidden" id="pn" name="pn"/>
                <input type="hidden" id="customer" name="customer"/>
                <table class="table">
                    <tr>
                        <td>Quantity to Receive:</td>
                        <td><input type="text" name="qty" /></td>
                    </tr>
                </table>
                </form>
            </center>
        </td>
    </tr>
</table>

This is my most recent attempt. I gave up on the first method and have started trying with this file. Still haven’t had any luck.

<?php
    $con = mysql_connect("localhost:3306","root","");
    if (!$con)
    {
        die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("pcu_ops", $con);

    $sql="SELECT * FROM common_parts ORDER BY customer ASC, category ASC, subcategory ASC, pn ASC";

    $result=mysql_query($sql,$con);

    if (!mysql_query($sql,$con))
    {
        die('Error: ' . mysql_error());
    }
?>
<table border="0">
    <colgroup>
        <col width="300px" valign="top">
        <col width="90%">
    </colgroup>
    <tr>
        <td valign="top">
            <!-- Add a <div> element where the tree should appear: -->
            <div id="common_parts_tree">
                <ul>
                    <?php
                        $row = mysql_fetch_array($result);
                            echo '<li class="expanded folder">'.$row['customer'];
                                echo '<ul>';
                                    while (($row['category'] != NULL) && ($row['subcategory'] != NULL)) {
                                        echo '<li class="expanded folder">'.$row['category'];
                                            echo '<ul>';
                                                echo '<li class="expanded folder">'.$row['subcategory'];
                                                    echo '<ul>';
                                                        echo '<li><a href="includes/phpscripts/part_quick_view.php?pn='.$row['pn'].'&customer='.$row['customer'].'" target="contentFrame">'.$row['pn'].'</a>';
                                                    echo '</ul>';
                                            echo '</ul>';
                                    }
                                echo '</ul>';
                    ?>
            </div>
        </td>
        <td>
            <iframe src="" name="contentFrame" width="100%" height="500" scrolling="yes" marginheight="0" marginwidth="0" frameborder="0">
                <p>Your browser does not support iframes</p>
            </iframe>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <center>
                <form id="rcv_common_parts">
                <input type="hidden" id="pn" name="pn"/>
                <input type="hidden" id="customer" name="customer"/>
                <table class="table">
                    <tr>
                        <td>Quantity to Receive:</td>
                        <td><input type="text" name="qty" /></td>
                    </tr>
                </table>
                </form>
            </center>
        </td>
    </tr>
</table>

Sure hope someone can help!

Thanks!

  • 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-03T20:10:02+00:00Added an answer on June 3, 2026 at 8:10 pm

    You should implement recursive algorithm.

    A tip for database…
    Simple example with categories and parts only:

     - Category1
            - Subcategory1
                    - Part1
                    - Part2
            - Subcategory2
                    - Part3
        - Category2
            - Subcategory3
                    - Part4
            - Part5
            - Part6
        - Part7 
        - Part8
    
    Categories_table
    id name          parent     user_id
    1  category 1    0          1
    2  category 2    0          1
    3  Subcategory1  1          1
    4  Subcategory2  1          1
    5  Subcategory3  2          1
    Parts_table
    name     category
    Part1    3
    Part2    3
    Part3    4
    Part4    5
    Part5    2
    Part6    2
    Part7    0
    Part8    0

    You get the point…

    Then for show:

     $query_user = mysql_query("select * from users",$con);
    while($row_user = mysql_fetch_array($query_user)) {
        echo "<ul>".$row_user['id'];
        show_category($row_user['id'],0);
        echo "</ul>";
    }
    function show_category($user,$parent){
        global $con;
        echo "<ul>";
        $query_cat = mysql_query("select * from categories where user_id=".$user." and parent=".$parent,$con);
        while($row_cat = mysql_fetch_array($query_cat)) {
            echo "<li>".$row_cat['name'];
            show_category($user,$row_cat['id']);
            echo "</li>";       
        }
        $query_parts = mysql_query("select * from parts where category=".$parent,$con);
        while($row_parts = mysql_fetch_array($query_parts)) {
            echo "<li>".$row_parts['name']."</li>";
        }
        echo "</ul>";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on this problem for a while now. I am trying
I have been working on this for 24 hours now, trying to optimize it.
Have been working on this question for a couple hours and have come close
I have been working on this app for at least 3-4 months and just
I have been working on this sort of ATM (With a maximum of 50
I have been working on this for few hours and got stuck, so how
I have been working on this application that enables user to log in into
I have been working on this problem for 2 days now and it's an
I have been working on this for days but I don't get it so
I have been working on this for some time now and just cant quite

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.