duandu2159 2014-11-24 15:04
浏览 12
已采纳

根据订购的商品设置总数,有两种类型,有时一种类型不会被订购。

Ok, I am kicking myself, because I had this giving me a total before, but now, It does not grab ALL items chosen for sale, and it does not total correctly. How do I get this to total correctly. There are two types of products and two tables populating these rows, one type is OrderIn_Id and the other is OrderOut_Id. The products are populating perfectly, just not getting a total, and gives me an error of underfined variable, if a person only chooses one type of product, like the OrderIn_id products, then PriceOut gives an error of undefined variable. Can you help?

<?php
echo "<table class='middlecheckOut'> 
<tr>
<td class='td2'><b>Order ID: </b></td>
<td class='td2'><b>Product Name: </b></td>
<td class='td2'><b>Quantity: </b></td>
<td class='td2'><b>Price: </b></td>
</tr>";

if (isset($_GET['user_id'])) {     
    $user_id = $_GET['user_id']; 
} elseif (isset($_POST['user_id']))  {    
    $user_id = $_POST['user_id'];
} 

$display="SELECT * 
    FROM order_instate JOIN in_Product ON 
    order_instate.ip_id = in_product.ip_id
    WHERE user_id = '$user_id'; " ; 

$displayResult = @mysqli_query($dbhandle, $display)
            or die(mysqli_error($dbhandle));

while($row = mysqli_fetch_array($displayResult, MYSQLI_ASSOC)) { 
    if($row['orderIn_complete'] == "No") {      
echo "<tr>
<td class='td2'>" . $row['orderIn_id'] . " &nbsp&nbsp</td>
<td class='td2'>" . $row['ip_name'] . " &nbsp&nbsp</td>
<td class='td2'>" . $row['orderIn_quantity'] . " &nbsp&nbsp</td>
<td class='td2'>$" . $row['orderIn_total'] . " &nbsp&nbsp</td>
 </tr>";
 $priceIn = NULL;
 $priceIn += $row['orderIn_total'];
    }
 }

 if (isset($_GET['user_id'])) {     
    $user_id = $_GET['user_id']; 
} elseif (isset($_POST['user_id']))  {    
    $user_id = $_POST['user_id'];
} 

$display2="SELECT * 
    FROM order_outstate JOIN op_Product ON 
    order_outstate.op_id = op_product.op_id
    WHERE user_id = '$user_id'; " ; 

$displayResult = @mysqli_query($dbhandle, $display2)
            or die(mysqli_error($dbhandle));

while($row2 = mysqli_fetch_array($displayResult, MYSQLI_ASSOC)) { 
    if($row2['orderOut_complete'] == "No") {        
echo "<tr>
<td class='td2'>" . $row2['orderOut_id'] . " &nbsp&nbsp</td>
<td class='td2'>" . $row2['op_name'] . " &nbsp&nbsp</td>
<td class='td2'>" . $row2['orderOut_quantity'] . " &nbsp&nbsp</td>
<td class='td2'>$" . $row2['orderOut_total'] . " &nbsp&nbsp</td>
 </tr>";
  $priceOut = NULL;
 $priceOut += $row2['orderOut_total'];
    }
 }
echo "</table>";

$subtotal = 0;
$tax = 0;
$gtotal = 0;
$subtotal = number_format($priceIn + $priceOut, 2);
$tax = number_format($subtotal * .074, 2);
$gtotal = number_format($subtotal + $tax, 2);

?>
  • 写回答

2条回答 默认 最新

  • dthtvk3666 2014-11-24 15:14
    关注

    Does this work?

    <?php
    echo "<table class='middlecheckOut'> 
    <tr>
    <td class='td2'><b>Order ID: </b></td>
    <td class='td2'><b>Product Name: </b></td>
    <td class='td2'><b>Quantity: </b></td>
    <td class='td2'><b>Price: </b></td>
    </tr>";
    
    if (isset($_GET['user_id'])) {     
        $user_id = $_GET['user_id']; 
    } elseif (isset($_POST['user_id']))  {    
        $user_id = $_POST['user_id'];
    } 
    
    $display="SELECT * 
        FROM order_instate JOIN in_Product ON 
        order_instate.ip_id = in_product.ip_id
        WHERE user_id = '$user_id'; " ; 
    
    $displayResult = @mysqli_query($dbhandle, $display)
                or die(mysqli_error($dbhandle));
    $priceIn = 0;
    while($row = mysqli_fetch_array($displayResult, MYSQLI_ASSOC)) { 
        if($row['orderIn_complete'] == "No") {      
    echo "<tr>
    <td class='td2'>" . $row['orderIn_id'] . " &nbsp&nbsp</td>
    <td class='td2'>" . $row['ip_name'] . " &nbsp&nbsp</td>
    <td class='td2'>" . $row['orderIn_quantity'] . " &nbsp&nbsp</td>
    <td class='td2'>$" . $row['orderIn_total'] . " &nbsp&nbsp</td>
     </tr>";
    
     $priceIn += $row['orderIn_total'];
        }
     }
    
     if (isset($_GET['user_id'])) {     
        $user_id = $_GET['user_id']; 
    } elseif (isset($_POST['user_id']))  {    
        $user_id = $_POST['user_id'];
    } 
    
    $display2="SELECT * 
        FROM order_outstate JOIN op_Product ON 
        order_outstate.op_id = op_product.op_id
        WHERE user_id = '$user_id'; " ; 
    
    $displayResult = @mysqli_query($dbhandle, $display2)
                or die(mysqli_error($dbhandle));
    
    $priceOut = 0;
    while($row2 = mysqli_fetch_array($displayResult, MYSQLI_ASSOC)) { 
        if($row2['orderOut_complete'] == "No") {        
    echo "<tr>
    <td class='td2'>" . $row2['orderOut_id'] . " &nbsp&nbsp</td>
    <td class='td2'>" . $row2['op_name'] . " &nbsp&nbsp</td>
    <td class='td2'>" . $row2['orderOut_quantity'] . " &nbsp&nbsp</td>
    <td class='td2'>$" . $row2['orderOut_total'] . " &nbsp&nbsp</td>
     </tr>";
    
     $priceOut += $row2['orderOut_total'];
        }
     }
    echo "</table>";
    
    $subtotal = 0;
    $tax = 0;
    $gtotal = 0;
    $subtotal = number_format($priceIn + $priceOut, 2);
    $tax = number_format($subtotal * .074, 2);
    $gtotal = number_format($subtotal + $tax, 2);
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器