$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;
}
在该代码之后,我想更新一个表格,并在列中插入每行的价格。至于我回声$total
我只回到了一排......
答案 0 :(得分:1)
尝试此操作
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 />' ;
}
编辑:
insert into ammounts (Total_Cost) VALUES ('total($datef,$dates,$rprice)')
WHERE id = '$row["id"]'
答案 1 :(得分:0)
假设您的order_id
表中有total
列作为PRIMARY KEY和orders
列。
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 />' ;
}