need to substract data current row-previous row in php

abhijeet2021

Broken In
while ($db_fields = pg_fetch_assoc($results)) {
if(date("Y-m-d")==$db_fields['dt'])
{
break;
}else
{
print "<tr><td>" . $db_fields['dt'] . "</td>";
print "<td>" . $db_fields['count'] . "</td></tr>";
}
}

as you can see in the sample code the loop gives me data somewhat like this

Date Count
2011-1-1 200
2011-1-2 250
2011-1-3 300
2011-1-4 150

now i want to insert a code in the while loop so that i get a custom 3rd column with output something like this


Date Count Diff
2011-1-1 200
2011-1-2 250 50
2011-1-3 310 60
2011-1-4 150 -150

kindly someone help me with the logic behind it
all coding is being done in php
 
Top Bottom