我正在尝试更新有多个商品的购物车中的数量,
例如 -
var get id of order item
var get quantity
post both to updateqty.php
订购多行时,有多个文本框的 id 为 qty 和多个隐藏输入的 id 为 part 所以它只能在它在该页面上找到的第一个 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."'";
它是 html 中的 ids,有多个 NOT THE MYSQL TABLE
所以我需要它来获取购物车中产品的 id 并通过 ajax 更新该 id 的数量
脚本的重要部分是
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>
";
}
提前致谢