Jump to content


Photo

Adding two values


  • Please log in to reply
1 reply to this topic

#1 Canman2005

Canman2005
  • Members
  • PipPipPip
  • Advanced Member
  • 669 posts

Posted 05 March 2006 - 01:45 PM

Dear all

I have a simple sql statement which adds up all the numbers in one colum of my database, the code I used is

$sql ="SELECT SUM(cost) as 'cost' FROM results WHERE resultid = '$resultid'";
$sql = @mysql_query($total,$connection) or die(mysql_error());

As well as the colum "cost" I also have another colum in my database called "costtwo"

How can I get the statement to add these two coloums (cost + costtwo) and then total the rows up? Basically like it does now, but adding costtwo before it tots up the rest of the values

Is this easy?

Thanks

Dave

#2 JasperBosch

JasperBosch
  • New Members
  • Pip
  • Newbie
  • 8 posts
  • LocationApeldoorn, The Netherlands

Posted 05 March 2006 - 07:28 PM

Hi,

You mean something like this?
$sql ="SELECT SUM(cost + costtwo) as 'cost' FROM results WHERE resultid = '$resultid'";
$sql = @mysql_query($total,$connection) or die(mysql_error());

Yea, thats realy easy, isn't it?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users