Let's discuss on how to make addition or summation the table row values in MySQL database with using PHP Development.
DOWNLOAD LIVE DEMO
Check out the below image, which is a demo of the addition the database values using PHP. Also, you can see the output values in the last row. Let's move onto the code.s
DATABASE
<?php
$conn=mysql_connect('localhost','root','');
$db=mysql_select_db('2my4edge',$conn);
?>
CODE
<table>
<tr>
<td class="head" >S No</td>
<td class="head">Mark</td>
<td class="head">Mark 1</td>
</tr>
<?php
include('db.php');
$table=mysql_query('SELECT * FROM `add`');
while($row=mysql_fetch_array($table))
{
$number=$row['id'];
$smark=$row['mark'];
$smark1=$row['mark1'];
?>
<tr>
<td class="sno"><?php echo $number ?></td>
<td class="mark"><?php echo $smark ?></td>
<td class="mark"><?php echo $smark1 ?></td>
</tr>
<?php } ?>
<?php
$add=mysql_query('SELECT SUM(mark),SUM(mark1) from `add`');
while($row1=mysql_fetch_array($add))
{
$mark=$row1['SUM(mark)'];
$mark1=$row1['SUM(mark1)'];
?>
<tr>
<td class="foot">Total</td>
<td class="foot"><?php echo $mark ?></td>
<td class="foot"><?php echo $mark1 ?></td>
</tr>
<?php } ?>
</table>
DOWNLOAD LIVE DEMO
Check out the below image, which is a demo of the addition the database values using PHP. Also, you can see the output values in the last row. Let's move onto the code.s
DATABASE
<?php
$conn=mysql_connect('localhost','root','');
$db=mysql_select_db('2my4edge',$conn);
?>
CODE
<table>
<tr>
<td class="head" >S No</td>
<td class="head">Mark</td>
<td class="head">Mark 1</td>
</tr>
<?php
include('db.php');
$table=mysql_query('SELECT * FROM `add`');
while($row=mysql_fetch_array($table))
{
$number=$row['id'];
$smark=$row['mark'];
$smark1=$row['mark1'];
?>
<tr>
<td class="sno"><?php echo $number ?></td>
<td class="mark"><?php echo $smark ?></td>
<td class="mark"><?php echo $smark1 ?></td>
</tr>
<?php } ?>
<?php
$add=mysql_query('SELECT SUM(mark),SUM(mark1) from `add`');
while($row1=mysql_fetch_array($add))
{
$mark=$row1['SUM(mark)'];
$mark1=$row1['SUM(mark1)'];
?>
<tr>
<td class="foot">Total</td>
<td class="foot"><?php echo $mark ?></td>
<td class="foot"><?php echo $mark1 ?></td>
</tr>
<?php } ?>
</table>
0 comments:
Post a Comment