计算总数时输出不正确


Incorrect output when calculating totals

我有一个网页,我可以在excel上导出一个。csv文件。发票从我的数据库中提取数据,以使用以下列计算total和grand total:

quantity, packing_price, courier_price

我注意到,当价格前面包含'£'声音时,我的代码不能输出正确的答案。是否有一种方法,我可以使这两个数字和货币数据类型的工作?

代码:

$output2= "";
$sql2 = mysql_query("
SELECT j.date
     , j.order_ref
     , j.quantity
     , j.packing_price
     , j.dispatch_type
     , j.courier_price 
  FROM Jobs j
 WHERE j.order_type = 'Retail International' 
   AND j.confirmed = 'Yes';
");
$columns_total2 = mysql_num_fields($sql2);
$total3 = "Total";
for ($i = 0; $i < $columns_total2; $i++)
{
    $heading2 = mysql_field_name($sql2, $i);
    $output2 .= '"'.$heading2.'",';
}
$output2 .= $total3;
$output2 .="'n";
$sum2 = 0;
while ($row = mysql_fetch_array($sql2)) {
    for ($i = 0; $i < $columns_total2; $i++) {
        $output2 .='"'.$row["$i"].'",';
    }
    $qty2 = $row['quantity'];
    $pack_price2 = $row['packing_price'];
    $dispatch2 = $row['courier_price'];
    $total2 =  (($qty2*$pack_price2) + $dispatch2);
    $total3 = $total2*1.2;
    $output2 .= $total3;
    $sum2 += $total3; // Add to overall total
    $output2 .="'n";
}
输出:

http://i754.photobucket.com/albums/xx182/rache_R/Screenshot2014-07-03at113133_zpsbcc09900.png

使用此代码....

$output= "<table border='1' width='60%'><tr>";
$sql = " SELECT j.date ,
                j.order_ref ,
                j.quantity ,
                j.packing_price ,
                j.dispatch_type ,
                j.courier_price 
           FROM Jobs j
          WHERE j.order_type = 'Retail International' 
            AND j.confirmed = 'Yes' ";
$query = mysql_query($sql);
$total_columns = mysql_num_fields($query);
for ($i = 0; $i < $total_columns; $i++){
    $heading = mysql_field_name($query, $i);
    $output .= '<td>' . $heading . '</td>';
    if(($i+1) == $total_columns)  $output .= '<td>Total</td></tr>';
}
while ($row = mysql_fetch_array($query)) {
    $total_price = 0;
    $total_price =( ( $row['quantity'] * $row['packing_price'] ) + 
                      $row['courier_price'] );
    $total_price = $total_price * 1.2;
    $timestamp = DateTime::createFromFormat('Y-m-d h:i:s',  
                 $row['date'])->getTimestamp();
    $output .= '<tr>'; 
    $output .= '<td>' . date("d/m/Y", $timestamp) . '</td>';
    $output .= '<tr>'; 
    $output .= '<td>' . date("d/m/Y", strtotime($row['date']) . '</td>';
    $output .= '<td>' . $row['order_ref'] . '</td>';
    $output .= '<td>' . $row['quantity']. '</td>';
    $output .= '<td>' . $row['packing_price'] . '</td>';
    $output .= '<td>' . $row['dispatch_type'] . '</td>';
    $output .= '<td>' . $row['courier_price'] . '</td>';
    $output .= '<td>' . number_format($total_price, 2) . '</td>';
    $output .= '</tr>'; 
}
$output .= "</table>";
echo '<br>' . $output;