-2

複数の商品があるカートで数量を更新しようとしていますが、

例えば ​​-

var get id of order item
var get quantity
post both to updateqty.php

複数の行が注文されている場合、qty の ID を持つ複数のテキスト ボックスと、part の ID を持つ複数の非表示の入力があるため、そのページで最初に見つかった ID でのみ機能します。他のアイテムを更新できるようにする必要があります。オーダー、

たとえば

get class of the textbox, then find out which qty is being updated, then update the quantity of the item.

誰かがこれを行う方法を知っていれば、それをいただければ幸いです。

<script>


function updateqty() {
    var ud_first = document.getElementById('part').value;
    var ud_last = document.getElementById('qty').value;

    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById("cart").innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET", "php/updateqty.php?order=<?php echo $order; ?>&id=" + ud_first + "&qty="+ud_last, true);
    xmlhttp.send();
}
</script>
<?php 


$sql="SELECT * FROM `orders` WHERE  `invoice` = '".$order."' ORDER BY id DESC";

$result = mysql_query($sql);
echo"
     <table id='POITable' width='100%' border='1'>
        <tr>
            <td>SKU</td>
            <td>QTY</td>
            <td width='45%'>item</td>
            <td>Unit Price</td>
            <td>Line Price</td>
            <td>Delete</td>
        </tr>";
while($row = mysql_fetch_array($result))
  {
echo"<tr><td>" . $row['part'] . "</td><td><form name='test'>
   <input type='hidden' value='" . $row[id] . "' id='part'>   <input type='text' id='qty' value='" . $row['qty'] . "' onblur='updateqty(this.id)'></form></td><td>" . $row['description'] . "</td><td>" . $row['price'] . "</td><td>" . $row['lineprice'] . "</td><td> <input type='image' src='images/btn_delete.png' value='" . $row[id] . "' onclick='deletesku(this.value)' height='30'/></td>
";

 }
?>  

挿入phpは

$id=$_GET[id];

$sql2="SELECT * FROM  `orders` WHERE  `id` = '".$id."'";

$result2 = mysql_query($sql2);

$row2 = mysql_fetch_array($result2);

$order=$_GET[order];
$qty=$_GET[qty];

$sql="SELECT * FROM  `stock` WHERE  `part` = '".$part."'";

$result = mysql_query($sql);

$row1 = mysql_fetch_array($result);

$lineprice=$qty * $row2[price];

$sqlins1 = "UPDATE `orders` SET qty='$qty', lineprice='$lineprice' WHERE id = '".$id."'";

NOT THE MYSQL TABLEの倍数があるのはhtmlのIDです

そのため、カート内の製品のIDを取得し、そのIDの数量をajaxで更新する必要があります

スクリプトの重要な部分は

    function updateqty() {
        var ud_first = document.getElementById('part').value;
        var ud_last = document.getElementById('qty').value;

        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("cart").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET", "php/updateqty.php?order=<?php echo $order; ?>&id=" + ud_first + "&qty="+ud_last, true);
        xmlhttp.send();
    }
    </script>
    <?php 


    $sql="SELECT * FROM `orders` WHERE  `invoice` = '".$order."' ORDER BY id DESC";

    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result))
      {
    echo"<tr><td>" . $row['part'] . "</td>

<td>

    <form name='test'>
           <input type='hidden' value='" . $row[id] . "' id='part'>
       <input type='text' id='qty' value='" . $row['qty'] . "' onblur='updateqty(this.id)'></form>

    </td><td>" . $row['description'] . "</td><td>" . $row['price'] . "</td><td>" . $row['lineprice'] . "</td><td> <input type='image' src='images/btn_delete.png' value='" . $row[id] . "' onclick='deletesku(this.value)' height='30'/></td>
        ";

         }

前もって感謝します

4

2 に答える 2

-1
    function updateqty() {  

    var str="$(this).attr('name')"; 
    var orderCode=str.slice(9,-1);
    var quantity = $(this).value;  

          if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {

    xmlhttp.open("GET","updateqty.php?order=<?php echo $order; ?>&id=" + orderCode + "&qty=" + quantity,true);
    xmlhttp.send();
    }

    </script>


    <div id="cart">
    <?php
    $sql="SELECT * FROM `orders` WHERE  `invoice` = '".$order."' ORDER BY id DESC";

    $result = mysql_query($sql);
    echo"
       <table id='POITable' width='100%' border='1'>
            <tr>
                <td>SKU</td>
                <td>QTY</td>
                <td width='45%'>item</td>
                <td>Unit Price</td>
                <td>Line Price</td>
                <td>Delete</td>
            </tr>";
    while($row = mysql_fetch_array($result))
      {
    echo"<tr><td>" . $row['part'] . "</td><td>
    <input type='text' name='quantity[779]' size='3' value='" . $row['qty'] . "' tabindex='1' onblur='updateqty(this.value)' />

</td><td>" . $row['description'] . "</td><td>" . $row['price'] . "</td><td>" . $row['lineprice'] . "</td><td><img src='images/btn_delete.png' onclick='deleteRow(this)' height='30'/></td>
";
 }
于 2013-05-13T12:01:06.613 に答える