Jump to content

Adding up column values


tobimichigan

Recommended Posts

Please code pros could anyone pls tell how to add up figs in a column? Say monthly deposits;

s/n name monthly_deposits month

1    Sd        $34567              July

2    Sid      $34567              August

 

Suppose I were to add up the 2 monthly deposits how do I do this?

 

I certainly know I'd have to draw out the query such that:

<?php
$select=mysql_query("select * from members");
$row=mysql_fetch_array($select);

$total=0;
$monthly_deposits =$row[monthly_deposits];
$name=$row[name];
$total+=$monthly_deposits;

echo ("$total");
?>

 

How do I add up the successive monthly deposits?

Link to comment
https://forums.phpfreaks.com/topic/187336-adding-up-column-values/
Share on other sites

Gents,

I'd asked this question before now. But the answer I got was not satisfying.

Here is it.

I have a table.. called Students with fields:

 

id  Name Units

1  Fg      5

2.  Hy      6

3.  Rt        4

 

Now I want the php code to add up units col values. Now I know I have to draw out the qry in an array:

 

<?php
$con=mysql_connect("localhost","root","");
$sel=mysql_query("select * from Units");
$res=mysql_fetch_array('$sel',$con);

$Units=$res[units];
?>

I want to add up the units and display them on a browser.

Please a precise answer as to how to go about this would be appreciated. Thank you.

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.