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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:24:28+00:00 2026-06-13T01:24:28+00:00

For an accounting system, I’m using PHP & MySQL. I’ve two tables GROUP and

  • 0

For an accounting system, I’m using PHP & MySQL. I’ve two tables “GROUP” and “ACHEADS”.

In the GROUP table, I have:

---------------------
| id (AI) |  group  |
---------------------
|    1    | Group 1 |
|    2    | Group 2 |
---------------------

In the ACHEADS table, I have:

-----------------------------------------
| id (AI) |  ac_head    | amount | j_id |
-----------------------------------------
|    1    | Something 1 |  2000  |   1  |
|    2    | Something 2 |  1000  |   1  |
|    3    | Something 3 |  5000  |   2  |
|    4    | Something 4 |  4000  |   2  |
|    5    | Something 5 |  8000  |   2  |
-----------------------------------------

I’ve joined the two tables as GROUP.id <<->> ACHEADS.j_id

Now I need to preview the data like this:

----------------------------------------------
Particulars               | Details | Total  |
----------------------------------------------
Group 1                   |         |        |
 Something 1              |    2000 |        |
 Something 2              |    1000 |   3000 |
----------------------------------------------
Group 2                   |         |        |
 Something 3              |    5000 |        |
 Something 4              |    4000 |        |
 Something 5              |    8000 |  17000 |
----------------------------------------------
GRAND TOTAL               |         |  20000 |
------------------------------------==========

Challenges

  1. The table will be dynamic and will generate within a PHP loop (I’m
    using a WHILE loop)
  2. Remember: it’s a table and if I miss echoing a td, then the table will break up

Problems

  • When I’m using the loop it’s echoing the data on the Details td
    accurately. But the sum of the details row according to j_id is also
    echoing in each td

Preview here:

----------------------------------------------
Particulars               | Details | Total  |
----------------------------------------------
Group 1                   |         |        |
 Something 1              |    2000 |   3000 |
 Something 2              |    1000 |   3000 |
----------------------------------------------
Group 2                   |         |        |
 Something 3              |    5000 |  17000 |
 Something 4              |    4000 |  17000 |
 Something 5              |    8000 |  17000 |
----------------------------------------------

My thoughts

  • If I can check whether it is the last data of the query, if isset,
    then echo the total amount with it’s td. (But remember the
    Challenge#2)
  • Does it require a foreach loop?

I failed

  • I tried checking max(id), it works fine in SQL, but can’t use it in
    condition within a loop.

(If you still can’t understand me, then on the second phase, I’ll post my code.)

  • 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-13T01:24:30+00:00Added an answer on June 13, 2026 at 1:24 am

    I would do 2 loops:

    1. Fetch id from GROUP
    2. Fetch amount from ACHEADS based on j_id

    This would look something like (non-tested code):

    echo '<table><tr><td>Particulars</td><td>Details</td><td>Total</td></tr>';
    
    $total = 0;
    
    $q1 = "SELECT id FROM `GROUP`";
    $res1 = mysqli_query($q1);
    while($row1 = mysqli_fetch_assoc($res1)) {
        echo 
    
        $group_total = 0;
        $j_id = $row1[id];
    
        $q2 = "SELECT ac_head, amount FROM ACHEADS WHERE j_id = $j_id";
        $res2 = mysqli_query($q2);
        while($row2 = mysqli_fetch_assoc($res1)) {
    
            echo '<tr><td>' . $row2[ac_head] . '</td>';
            echo '<td>' . $row2[amount] . '</td></tr>';
    
            $group_total = $group_total + $row2[amount];
            $total = $total + $row[amount];
        }
    
       echo '<tr><td colspan="3" align="right">' . $group_total . '</td></tr>';
    }
    
    echo '<tr><td>GRAND TOTAL</td>';
    echo '<td colspan="2" align="right">' . $total . '</td></tr>';
    echo "</table>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am designing an online accounting system as a college project. I have got
I have a payments table that has a user_id and an amount. Users have
I want to update a customer table with a spreadsheet from our accounting system.
i am new in project for company that have bigger enterprise/accounting system based on
Well, my question is about Accounting Management. I have a system already, it's work
I am currently trying to optimize a report using mysql and openreports for accounting
We are developing an enterprise-size accounting system and we have logical design problem which
i am going to create a database for double-entry accounting system in MySQL. i
We need to get data out of an older accounting system. We have received
We have accounting software populating the name field on a magento webstore, the problem

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.