tobimichigan Posted January 5, 2010 Share Posted January 5, 2010 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? Quote Link to comment Share on other sites More sharing options...
trq Posted January 6, 2010 Share Posted January 6, 2010 SELECT SUM(monthly_deposits) FROM members Quote Link to comment Share on other sites More sharing options...
tobimichigan Posted January 13, 2010 Author Share Posted January 13, 2010 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. Quote Link to comment Share on other sites More sharing options...
trq Posted January 13, 2010 Share Posted January 13, 2010 This is not a math problem and can be quite easily achived using a simple query. <?php if ($result = mysql_query("SELECT SUM(Units) as total")) { $row = mysql_fetch_assoc($result); echo $row['total']; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.