Php Help

Status
Not open for further replies.

iorrasnet

New Member
Hi. I a a newbie at PHP.

I have two pieces of data which I am retrieving from a database. They are both numerical values.

They are part of a wider data list which is being retrieved from the database and displayed on the web site

Like this :
2007 2008 Difference
John 100 110
Mary 130 120
Ann 96 98

I wnat to be able to calculate, using PHP the Diffference cloumn as each is being displayed. ie to take the 2008 value and the 2007 value for each associated with each name and calculate the difference.

Any thoughts ?
 

louie

New Member
Code:
 result = value1 - value2 ;
echo result;

Is just too simple or I didn't get the question.
 

iorrasnet

New Member
Thanks Louie

I may not have explained myself well enough. I did try that and as you say the coding is simple. However my problem is getting it to do the calculation and output the result for all the records in the records set. The two values are coming in from the record set and i wnat the calculated value to be output with the recordset.

Thanks
 

iorrasnet

New Member
passing values

Thanks for your help louie.

I got a calculcation to work inside the loop (while statement)

What I am now stuck on is assigning the data to the variables in the calculation. So what I have now is

$result = $x-$y;
echo $result;

I am getting stuck on the syntax to assign values from the recordset to $x and $y. The values are being pulled from the database ok because I have been able to output them.

Iorrasnet
 

jmcc

Active Member
Why not have the database do the calculations (just tweak the SQL so that you have $x,$y,$diff returned) and then read back the values or just the difference?

Regards...jmcc
 

iorrasnet

New Member
I did think of that........but then couldn't figure out how to get the database to do the calculation to give me $diff :)
 
Status
Not open for further replies.
Top