如何使用数组基于增量数量增加总量?

时间:2018-06-11 02:34:58

标签: arrays cart

我是这个购物车项目的新手。我想增加和减少数量,并根据qty.Below它的代码初始我使用数组显示db的产品.javascript条件仅适用于第一行。我不知道如何使用数组执行此操作?

<table class="table">
        <thead>
            <tr>
                <th>Product</th>
                <th>Price</th>
                <th>Quantity</th>
                <th>Subtotal</th>
                <th>Remove</th>
            </tr>
            <?php
             $querysql = "SELECT * FROM purchase_item WHERE custname = '$finalcustomer'";                     

        $resultquerysql = $conn->query($querysql); 

        if ( $resultquerysql->num_rows > 0 )
        {
            while($rowquerysql = $resultquerysql->fetch_assoc())
                     { 
                        $array[] = $rowquerysql;
                        //$productnew = $rowquerysql['product'];
                       // $pricenew = $rowquerysql['price'];
                        //$qtynew = $rowquerysql['qty'];
                        //$totalnew = $rowquerysql['total'];
                     }
                      }
                 for($k=0;$k<sizeof($array);$k++)
             {
        ?>
            <tr>
            <td>
             <input type="hidden" name="custid[]" value="<?php  echo $array[$k]['cust_id']; ?>" id="amountee"/>
            <input type="hidden" name="productname[]"  value="<?php  echo $array[$k]['product'];?>"id="itemname" /><?php echo $array[$k]['product'];?> 
            </td>
            <td>
            <input type="hidden" name="productamount[]" value="<?php  echo $array[$k]['price']; ?>" id="amount"/><?php echo $array[$k]['price'];?>
            </td>
            <td><input type="number" name="productqty[]" value="<?php echo $array[$k]['qty'];?>" id="qty"/></td>
            <td><input type="text" name="producttotal[]" value="<?php echo $array[$k]['total']?>" id="total" /> </td>
          <td><a href="javascript:void(0)" class="btn btn-danger remove_btn" ><i class="glyphicon glyphicon-trash" style="position: relative;z-index: 999;"></i></a>
                            </td>
            </tr>
            <?php } 

           ?>

           </thead>
           </table>

的Javascript

 $(document).ready(function(){
      $("#qty").on('change',function() {
        //alert("ji");

        var priceaqtyold = document.getElementById('qty').value;
   // alert(priceaqtyold);
  var priceamountold = document.getElementById('amount').value;
      // alert(priceamountold);
        var amountnewold = priceamountold * priceaqtyold;
     //alert(amountnewold);
       $('#total').val(amountnewold);
           var priceamountoldww = document.getElementById('total').value;

      });
    })

0 个答案:

没有答案