$sql = mysql_query("SELECT * From orders");
while ($row = mysql_fetch_array($sql))
{
$datef = strtotime($row['Date1']);
$dates = strtotime($row['Date2']);
$rprice = $row['Pprice'];
$datediff = floor(($datef + $dates ) / 86400);
$total = $datediff * $rprice;
echo $total;
}
After that code, i want to update a table and insert into a colum the price for each of the rows. as far as i echo $total
i get back just 1 row...
try this if it works
function total($date1,$date2,$price){
$datedif = floor(($date1 + $date2 ) / 86400);
$total = $datedif * $price ;
return $total ;
}
$sql=mysql_query("SELECT * From orders");
while ($row = mysql_fetch_array($sql))
{ $datef = strtotime($row['Date1']);
$dates = strtotime($row['Date2']);
$rprice=$row['Pprice'];
echo total($datef,$dates,$rprice).'<br />' ;
}
EDIT:
insert into ammounts (Total_Cost) VALUES ('total($datef,$dates,$rprice)')
WHERE id = '$row["id"]'
suppose you have order_id
coulmn as PRIMARY KEY and total
column in your orders
table.
while ($row = mysql_fetch_array($sql))
{ $datef = strtotime($row['Date1']);
$dates = strtotime($row['Date2']);
$rprice=$row['Pprice'];
$total=total($datef,$dates,$rprice);
$query=mysql_query("UPDATE orders SET total = $total WHERE order_id = '$row[order_id]'") or die(mysql_error());
echo $total.'<br />' ;
}