-2
 $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我只回来了 1 行...

4

2 回答 2

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"]'
于 2013-04-25T19:07:55.273 回答
0

假设您在表中有order_id作为 PRIMARY KEY 和total列的库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 />' ;
 }
于 2013-04-25T19:42:33.413 回答