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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:53:52+00:00 2026-06-11T03:53:52+00:00

I’m making a table right now for displaying accounting data, with invoices broken up

  • 0

I’m making a table right now for displaying accounting data, with invoices broken up into license, year, half, and quarter. The invoices come from a query as a 2d array,like this:

array(
    'invoice0' = array(data),
    'invoice2' = array(data),
    'invoice3' = array(data),
    'invoice4' = array(data),
    'invoice5' = array(data),
    'invoice1' = array(data)
)

Currently I’m been using a four-deep nested foreach loop, which seems fairly evil, to create a 5d array structure to organize the rows, with data rows for every level. e.g.:

'License' = array(
  'Year0' = array(
    'Half0' = array(
      'Quarter0' = array(
        'invoice0' = array(data),
        'invoice1' = array(data)
      ),
      'QData' = array(data)
    ),
    'HData' = array(data)
    'Half1' = array(
      'Quarter0' = array(
        'invoice3' = array(data),
        'invoice4' = array(data)
      ),
      'Quarter1' = array(
        'invoice5' = array(data),
        'invoice6' = array(data)
      ),
      'QData' = array(data)
    ),
    'HData' = array(data)
  ),
  'YData' = array(data)
)

And so on. The data for each level needs to include a sum of an amount in the data for each invoice. The end product I’m trying to achieve is simply a bunch of rows of a table (or list items; I’m restricted to table structure for this project) That are expandable. So:

<tr>License info</tr>
<tr>License info</tr>
<tr>License info</tr>
<tr>License info</tr>

And when you click on one:

<tr>License info</tr>
<tr>License info</tr>
<tr>Year1 Info</tr>
<tr>Year2 Info</tr>
<tr>Year3 Info</tr>
<tr>License info</tr>
<tr>License info</tr>

Eventually:

<tr>License info</tr>
<tr>License info</tr>
<tr>Year1 Info</tr>
<tr>Year2 Info</tr>
<tr>Half1 Info</tr>
<tr>Quarter1 Info</tr>
<tr>Quarter2 Info</tr>
<tr>Invoice1 Info</tr>
<tr>Invoice2 Info</tr>
<tr>Invoice3 Info</tr>
<tr>Quarter3 Info</tr>
<tr>Quarter4 Info</tr>
<tr>Half2 Info</tr>
<tr>Year3 Info</tr>
<tr>License info</tr>
<tr>License info</tr>

So, any ideas? Is there any way to avoid such complex data manipulation while still getting me a 5-deep hierarchical dropdown list?

  • 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-11T03:53:54+00:00Added an answer on June 11, 2026 at 3:53 am

    Okay I didn’t understand completely what is it exactly you want, but I did this, kinda confusing, heh:

    function get_data($data, $level = 0)
    {
        $html = '';
    
        foreach ($data as $name => $val) {
            if (!is_int($name)) {
                if (!$level)
                    $html .= '<tr>';
                $html .= '<ul>';
                $html .= '<li><span class="parent">'.$name.'</span>';
                $html .= get_data($val, $level + 1);
                $html .= '</li></ul>';
                if (!$level)
                    $html .= '</tr>';
            } else {
                $html .= '<ul><li>'.$val.'</li></ul>';
            }
        }
        return $html;
    }
    

    The HTML should look like this (using jQuery):

    <style>
    span.parent {
        cursor:pointer;
    }
    ul ul {
        display:none;
    }
    </style>
    <table>
    <?php echo get_data($data) ?>
    </table>
    <script>
    $('span.parent').click(function(){
        if ($(this).hasClass('open')) {
            $(this).parent().children('ul').hide();
            $(this).removeClass('open');
        } else {
            $(this).parent().children().show();
            $(this).addClass('open');
        }
    })
    </script>
    

    I tried this out with the following array and… well it worked but, again, I don’t know if this is what you’re looking for.

    $data = array(
        'License' => array(
            'Year0' => array(
                'Half0' => array(
                    'Quarter0' => array(
                        'invoice0' => array('data'),
                        'invoice1' => array('data')
                    ),
                    'QData' => array('data')
                ),
                'HData' => array('data'),
                'Half1' => array(
                    'Quarter0' => array(
                        'invoice3' => array('data'),
                        'invoice4' => array('data')
                    ),
                    'Quarter1' => array(
                        'invoice5' => array('data'),
                        'invoice6' => array('data')
                    ),
                    'QData' => array('data')
                ),
                'HData' => array('data')
            ),
            'YData' => array('data')
        ),
    
        'License2' => array(
            'Year0' => array(
                'Half0' => array(
                    'Quarter0' => array(
                        'invoice0' => array('data'),
                        'invoice1' => array('data'),
                    ),
                    'QData' => array('data')
                ),
                'HData' => array('data'),
                'Half1' => array(
                    'Quarter0' => array(
                        'invoice3' => array('data'),
                        'invoice4' => array('data')
                    ),
                    'Quarter1' => array(
                        'invoice5' => array('data'),
                        'invoice6' => array('data')
                    ),
                    'QData' => array('data')
                ),
                'HData' => array('data')
            ),
            'YData' => array('data')
        )
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I want to construct a data frame in an Rcpp function, but when I
I'm making a simple page using Google Maps API 3. My first. One marker
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.