Please help something wrong I am a new b in programming.
<?php
include "dbcon1.php";
$sql = "SELECT date, price FROM `table1` ORDER BY table.date DESC";
$result = mysql_query($sql)
or die(mysql_error());
$my_header=<<<EOD
<h2><center>PROFIT ANALYSIS<font color="red" size="6"></h2>
<table width="70%" border="1" cellpadding="2"
cellspacing="2" align="center">
<tr>
<th>DATE</th>
<th>PRICE</th>
<th>DIFF</th>
</tr>
EOD;
$my_details = '';
$priordate = '';
$priorprice = null;
while ($row = mysql_fetch_array($result)) {
$date = $row['date'];
$price = $row['price'];
if ($priordate == '') {
$priordate = $date;
echo $priordate;
$priorprice = $price;
echo $priorprice;
}
echo $priorprice;// price captured remain as initial price
$diff = $priorprice - $price; //PRIORPRICE($priorprice) REMAIN UNCHANGED AS DATE CAPTURED REMAIN THE INITIAL DATE
$my_details .=<<<EOD
<tr>
<td>$date</td>
<td><font color="red" size="4"> $price</td>
<td><font color="red" size="4"> $diff</td>
</tr>
EOD;
}
$my_footer ="</table>";
$final =<<<RESULT
$my_header
$my_details
$my_footer
RESULT;
echo $final;
?>
MY RESULT
DATE PRICE DIFF
2009-08-01 1232 0
2009-08-04 1250 18
2009-08-05 1273 41
2009-08-19 1181 -51
PRICE DIFF DISPLAYED FROM THE START DATE
ACTUAL RESULT I EXPECT IS
DATE PRICE DIFF
2009-08-01 1232 0
2009-08-04 1250 18
2009-08-05 1273 23
2009-08-19 1181 -92
THE DATE IS NOT CAPTURING . PLEASE HELP ME. if loop ?