1

我正在尝试从 MYSQL_FETCH_ARRAY 中添加总计,但由于我使用 JOINS 来获取乘法定价,因此我无法在 SELECT 语句中使用 SUM。

我的代码如下以及我想要完成的截图。

   $qt2 = mysql_query("SELECT
   customer_specs.type, 
   customer_specs.stone, 
   customer_specs.sf,
   customer_specs.bs_ht,
   customer_specs.edge_1_lf,
   customer_specs.tearout_1_price, 
   customer_specs.tearout_1_sf, 
   customer_specs.cooktop_cutout_qty, 
   customer_specs.cooktop_cutout_price, 
   customer_specs.elect_outlet_qty, 
   customer_specs.elect_outlet_price, 
   customer_specs.sink_1_cutout, 
   customer_specs.sink_2_cutout,  
   stones.price AS stprice, 
   edging.price AS edprice, 
   s1.name AS s1name, 
   s2.name AS s2name, 
   s1.price AS s1price, 
   s2.price AS s2price  

   FROM customer_specs 
    INNER JOIN items 
    ON customer_specs.type=items.id
    INNER JOIN stones 
    ON customer_specs.stone=stones.id
    INNER JOIN edging 
    ON customer_specs.edge_1=edging.id
    INNER JOIN sinks AS s1 
    ON customer_specs.sink_1=s1.id
    INNER JOIN sinks AS s2 
    ON customer_specs.sink_2=s2.id

    WHERE quote = '$qte' AND c_id='$cid'");         
    while($qts2 = mysql_fetch_array( $qt2 )) 
    { 
    $edgep = $qts2['edprice'] * $qts2['edge_1_lf'];
    $stonep = $qts2['stprice'] * $qts2['sf'];
    $tearp = $qts2['tearout_1_sf'] * $qts2['tearout_1_price'];
    $cookp = $qts2['cooktop_cutout_price'] * $qts2['cooktop_cutout_qty'];
    $elecp = $qts2['elect_outlet_price'] * $qts2['elect_outlet_qty'];
    $sink1cp = $qts2['sink_1_cutout'];
    $sink2cp = $qts2['sink_2_cutout'];
    $sink1p = $qts2['s1price'];
    $sink2p = $qts2['s2price'];

    $total = $edgep + $stonep + $tearp + $cookp + $elecp + $sink1cp + $sink2cp+$sink1p + $sink2p;
    $money=$total;
    $formatted = number_format($money,2);
    Print "<td>$".$formatted."</td>";

截图可见:http ://www.quarrygranite.com/ss.jpg

提前感谢您的任何帮助。

4

0 回答 0