Here i'm going to tell about, how to make addition or sum the table row values in the mysql database using PHP, this concept is very simple one, let see how to make this addition in mysql database using PHP.

you know this, like the above sample image is the demo of the add or sum the database data values in the database using PHP, you can see the out put value in the last row the table. ok let see the code.
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>
i hope you can get clear idea from the above code. SUM(column-name) is very important. i hope this is very useful to everyone. Thank you.
RELATED POST :
Detect Operating System and Detect the Browser using Php
Marquee style in different manner with PHP and MySql
Arun kumar is back on fire :)
ReplyDeleteThis is great, Thank you
ReplyDelete--The word impossible says “I'm Possible”--
thats great solution. Thanks a lot. God Bless U.
ReplyDeleteThanks for the coding ya.........
ReplyDeleteGood one........................
ReplyDeleteThis was very helpful ........ Thank you
ReplyDeleteI have a similar problem to solve, only that the summation has to be along the row. Say the Total is a column head and we needed to have the total of Row 1 for Mark 1, Mark 2 and Mark3 as below
ReplyDeleteSTUDENT Mark 1 Mark 2 Mark 3 Total
John 45 50 49
Milton 44 50 47
Paul 48 45 49
Any suggestions?
Did you ever get an answer to this. I have the same problem.
DeleteThank you
Thanks...
ReplyDeletedatabase bhi de diya karo
ReplyDeletenice one.clear concept.thanks
ReplyDeleteThey have error show in this coding
ReplyDeleteWah Bhai, Gazab ka tutorial He, yaar.......
ReplyDelete