while loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nex
Forum Newbie
Posts: 5
Joined: Tue May 11, 2004 8:54 am

while loop

Post by nex »

Cant work out an algorithm to calculate the following:

I have 3 fields, 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 -

loop
$result = yesterday$close - today$open +today$close
echo $total

bellow my attempts to construct the loop

Code: Select all

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 am where sdate BETWEEN '2004-03-01' AND '2004-03-30'")
or die("SELECT error".mysql_error());

$open = mysql_query("select open from am 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;
}
}
Last edited by nex on Tue May 11, 2004 3:12 pm, edited 7 times in total.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

First off, please read this - viewtopic.php?t=21171
Post Reply