Connecting Tech Pros Worldwide Forums | Help | Site Map

compare data in php

Familiar Sight
 
Join Date: Jan 2008
Posts: 199
#1: Nov 28 '08
I' developing web application using php and mysql. In there every half an hour data receive and stored in the data base.
ex: 6:00am 2.3
6.30am 2.8
7:00am 3.0
Now i want to take the difference between current value and previous value and store. How can I do that?

nathj's Avatar
Expert
 
Join Date: May 2007
Location: North Tyneside
Posts: 857
#2: Nov 28 '08

re: compare data in php


It's difficult to tell with so little information but could you issue some SQL order by the unique ID DESC to give the records in reverse order then limit the output to 2 records. This would give you the 2 most recent records. Then you could calculate the difference and store it back tot he table.

That assumes you have an auto incremented unique ID - fairly standard so the process should work for you.

Cheers
nathj
Reply