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
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.

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.