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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:48:28+00:00 2026-05-31T14:48:28+00:00

I’m trying to figure out how to make this code work. Basically i have

  • 0

I’m trying to figure out how to make this code work. Basically i have used MySQL to fetch an associative array containing multiple values.

example database: database name = Products

 ----------------------------------------------------------------.
|   name     | overcategory |   category   |     subcategory     |
|  Talon     |    null      | stud welding | capacitor discharge |
| cdss m3x40 | studs/bolts  |   cd-studs   |   stainless steel   |
----------------------------------------------------------------.

I used the sentence SELECT name, overcategory, category, subcategory FROM Products WHERE 1 = 1;

In the actual database there are more entries, but they are not relevant for this question.

The result i want to output as a menu on the left hand side of the screen.

<nav>
   <h1> "$overcategory" </h1>
     <h2> "$category" </h2>
         <h3> "$subcategory" </h3>
           <a href = "">$productname </a>
           <a href = "">$productname3 </a>

   <h1> "$overcategory2" </h1>
     <h2> "$category2" </h2>
         <h3> "$subcategory2" </h3>
           <a href = "">$productname2 </a>
</nav>

i was thinking of doing this by creating a multidimensional array that would look something like this:

    $testArray = array(
        ''=>array(
              'Boltsveiseapparater'=>array(
                            'Kondensator'=>array(
                                         'Talon',
                                         'LBS-75'
                                        ),
                                    'Arc'=>array(
                                         'LBH-410',
                                         'LBH-800'
                                        )
                                  )
            ),
            'Pinner/bolter'=>array(
                                        'CD-pinner'=>array(
                                                            'rustfri'=>array(
                                                                            'cdss m3x35',
                                                                            'cdss m3x40'
                                                                            ),
                                                              'stål'=>array(
                                                                            'cdms m3x35',
                                                                            'cdms m6x35'
                                                                            ),
                                                                'Alu'=>array(
                                                                            'cdal m3x10',
                                                                            'cdal m8x80'
                                                                            )
                                                        ),
                                        'Bossinger'=>array(
                                                            'Stål'=>array(
                                                                            'M6x10 5x8',
                                                                            'M5x12 4x10'
                                                                            ),
                                                                'Alu'=>array(
                                                                            'M6x10 5x8',
                                                                            'M5x12 4x10'
                                                                            ),
                                                            'Rustfri'=>array(
                                                                            'M6x10 5x8',
                                                                            'M5x12 4x10'
                                                                            )
                                                        )
                                )

      );                                                                        

I have no idea how to do this by looping through the results. is there any way of doing this without making a giant array of doom? if not, can someone assist me in decyphering this conundrum.

Thank you in advance.
BM.

  • 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-31T14:48:29+00:00Added an answer on May 31, 2026 at 2:48 pm

    If you sort each of the columns of your results in your SQL query, you can just loop through each result and compare it with the last entry and adjust your output based on that.

    SELECT name, overcategory, category, subcategory FROM Products ORDER BY overcategory, category, subcategory, name;
    

    Otherwise, here is one way of handling your nested array:

    <?php
    
    echo "\n";
    echo "<nav>\n";
    foreach ($testArray as $overcategory_name => $category_data) {
        echo "\t<h1>$overcategory_name</h1>\n";
        foreach ($category_data as $category_name => $subcategory_data) {
            echo "\t\t<h2>$category_name</h2>\n";
            foreach ($subcategory_data as $subcategory_name => $product_name_data) {
                echo "\t\t\t<h3>$subcategory_name</h3>\n";
                foreach ($product_name_data as $product_name) {
                    echo "\t\t\t\t<a href = \"\">$product_name</a>\n";
                }
            }
        }
    }
    echo "</nav>\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.