Could anyone advise. Cant work out an algorithm to calculate the following:
I have 3 fields in the table, one contains morning price, 2nd contains evening price, 3rd containd the date.
I need to deduct from the evening price the morning price of the next day and add evening price of the same day - then loop in this fashion through 30 days to output the result for each day.
+------------+------+-------+
| sdate | open | close |
+------------+------+-------+
| 2004-03-01 | 43 | 43 |
| 2004-03-02 | 43 | 42 |
| 2004-03-03 | 42 | 43 |
| 2004-03-04 | 43 | 44 |
| 2004-03-05 | 44 | 44 |
| 2004-03-08 | 44 | 43 |
| 2004-03-09 | 43 | 43 |
| 2004-03-10 | 43 | 42 |
loop
$result = yesterday$close - today$open +today$close
echo $result
bellow my attempts to construct the loop
include ("include/dbconnection.inc");
$connection = mysql_connect($host,$dbuser,$dbpassword);
if(!$connection)
die("Couldnt connect");
mysql_select_db($database, $connection)
or die("couldnt connect to db".mysql_error());
$close = mysql_query("select close from amex where sdate BETWEEN '2004-03-01' AND '2004-03-30'")
or die("SELECT error".mysql_error());
$open = mysql_query("select open from amex where sdate BETWEEN '2004-03-02' AND '2004-03-30'")
or die("SELECT error".mysql_error());
############################
while($resclose = mysql_fetch_row($close)){
$total+=$resclose[0];
echo $total;
while($resopen = mysql_fetch_row($open)){
$total = 0;
$calc = $resclose[0];
$calc2 = $resopen[0];
$total = $calc - $calc2;
}
}
// this while isnt working
#############################