我試圖在有多個項目,一車更新量,AJAX更新數量其中id和數量
例如 - 訂單
var get id of order item
var get quantity
post both to updateqty.php
多行有與多個文本框身份證的數量和多個隱藏的輸入與零件的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."'";
它是在HTML IDS有
,所以我需要它來拿起一個產品的ID在不是MySQL表的倍數購物車,並通過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>
";
}
在此先感謝
遺憾的更新在另一個文件中,我要把這在現在的問題中,插入部分工作正常,雖然 – 2013-05-12 14:28:25
updateqty.php?order = <?php echo $ order; ?>&qty =「+ str是問題,它只在腳本使用時傳遞2個頭文件變量3.更新需要從$ id = $ _ GET [id]獲得的id(主鍵);但是你沒有傳遞一個ID在標題中,所以它永遠不會被分配 – 2013-05-12 14:35:27
它需要拿起ID但所有的ID都是相同的,所以我需要它告訴插入腳本哪一行更新通過哪個文本框更改 – 2013-05-12 14:44:22