Calculate Sum (Total) of Column in PHP
Submitted by jkev on Wednesday, May 15, 2013 - 13:19.
Language
Hi guys,
The purpose of this code is to teach you on how to calculate the values of a column using the Sum function.
This is very useful if you want to create a poin of sale system in your PHP project.
Hope you will like this source code, for more question about this code email me at [email protected] thank you.
databasename: db folder sum.sql
Sample code:
- <?php
- include('header.php');
- ?>
- <body>
- <br>
- <br>
- <div class="container">
- <div class="alert alert-success">Sum the Numbers in a Column</div>
- <br />
- <table class="table table-striped table-bordered">
- <thead>
- <tr>
- <th>Product Name</th>
- <th>Quantity</th>
- <th>Price</th>
- <th>Amount</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $id=$row['product_id'];
- ?>
- <tr>
- <td><?php echo $row['name'] ?></td>
- <td><?php echo $row['qty'] ?></td>
- <td><?php echo $row['Price'] ?></td>
- <td><?php echo $row['amount'] ?></td>
- </tr>
- <?php } ?>
- </tbody>
- </table>
- <?php
- ?>
- <div class="pull-right">
- <div class="span">
- <div class="alert alert-success"><i class="icon-credit-card icon-large"></i> Total: <?php echo $rows['sum(amount)']; ?></div>
- </div>
- </div>
- <?php }
- ?>
- <div class="pull-right">
- <div class="span">
- <div class="alert alert-info"><i class="icon-credit-card icon-large"></i> Total number of Items: <?php echo $rows1['sum(qty)']; ?></div>
- </div>
- </div>
- <?php } ?>
- </div>
- </body>
- </html>
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Comments
Add new comment
- Add new comment
- 11798 views