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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:55:22+00:00 2026-05-27T03:55:22+00:00

I have retrieved some values from database. In my view file I have the

  • 0

I have retrieved some values from database. In my view file I have the following:

 $row['fee_amount']; 

Now, I want to sum up all the values inside $row[‘fee_amount’]; and then show it.

I know I could sum up when querying the database, but I am interested to learn how to add using PHP .

Would you please kindly teach me how to do it?

EDIT

    <?php if(count($records) > 0) { ?>              
        <table id="table1" class="gtable sortable">
            <thead>
                <tr>                        
                    <th>S.N</th>
                    <th>Fee Type</th>
                    <th>Fee Amount</th>                         
                </tr>
            </thead>
            <tbody>             
                <?php $i = 0; foreach ($records as $row){ $i++; ?>
                    <tr>
                        <td><?php echo $i; ?>.</td>
                        <td><?php echo $row['fee_type'];?></td>                                                
                        <td><?php echo $row['fee_amount'];?></td>                                           
                    </tr>                                                                                          
                <?php  } ?>             
            </tbody>                
            <tr>                                                        
                <td></td>
                <td>Total</td>
                <td> 
                    I WANT TO DISPLAY THE SUMMATION RESULT HERE ADDING UP VALUES INSIDE THIS>>> <?  $row['fee_amount']; ?> 
                </td>                                                                               
            </tr>               
        </table>
    <?php } ?>
  • 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-27T03:55:23+00:00Added an answer on May 27, 2026 at 3:55 am

    In your view file, with your foreach loop, add a $sum variable next to your $i counter and add the amount per each iteration (similar to like you increase $i):

    <?php
        $i = 0;
        $sum = 0;
        foreach ($records as $row)
        { 
            $i++; 
            $sum += $row['fee_amount']; ?>
    

    (I put this over multiple lines to make it more readable).

    After the foreach has finished, $sum contains the total amount:

            <td>Total: <?php echo $sum; ?></td>
    

    That simple it is. You only need a new variable ($sum) and do the calculation.

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

Sidebar

Related Questions

I have some existing code that retrieves data from a database using ADO.NET that
I have a GridView which retrieves data from a database. Users have roles, some
I'm working with some data which is being retrieved from my database. It's placed
I have written some code to look at properties using reflection. I have retrieved
I am trying to parse some XML i have retrieved via e4x in an
I have a Rails app with some basic models. The website displays data retrieved
I have to develop a tool in C# that retrieves some data from an
So you have a String that is retrieved from an admin web UI (so
I'm doing some manipulation and retrieval of values stored in a table. Each row
I am trying to retrieve a set of values from database and assigned it

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.