我有一個表和每一行項目都有一個addtocart按鈕,當我點擊addtocart按鈕時,模式顯示,它有我想要訂購的數量的確定按鈕,當我單擊確定按鈕另一個模式將顯示,它具有表格形式,如第一個表格,它顯示我訂購的項目,當我單擊確定按鈕時,我希望將這些行插入到數據庫中。如何插入多個數據到表
$($table).delegate(".Addtocart", "click", function() {
var itemNo = $(this).closest('tr').find('td.itemNo').html();
var selected_item = $(this).closest('tr').find('td.itemdescr').html();
var remaining_qty = $(this).closest('tr').find('td.currqty').html();
var unitPrice = $(this).closest('tr').find('td.unit_price').html();
var amount = $(this).closest('tr').find('td.Amount').html();
$("#action").val('add');
$('#itemNo').val(itemNo);
$('#selected_item').val($.trim(selected_item));
$('#remaining_qty').val(remaining_qty);
$('#unitPrice').val(unitPrice);
$('#amount').val(amount);
$('#myModal').modal('show');
});
繼承人的第二個模式
$('#OKBtn2').click(function(){
$('#myModal2').modal('hide');
var itemid = $('#main-form2 .active').attr('id'),
qty = $('#main-form2 #'+itemid+' td:eq(2)').text(),
amount = $('#main-form2 #'+itemid+' td:eq(4)').text();
bootbox.confirm("Are you sure?","No","Yes",function(r){
if(r) {
var itemno = $('#itemNo').val();
// var currqty = $('#orderqty').val();
var unit_price = $('#unitPrice').val();
// var Amount = $('#amount').val();
$.ajax({
url : url,
type : "POST",
async : false,
data : {
Modify: 1,
Delete:1,
Add: 1,
itemNo: itemno,
orderqty: qty,
unit_price: unit_price,
amount: amount,
todo:"Add"
},
success:function(result){
bootbox.alert('Ordered',function(){
});
updateTable();
}
});
} else {
}
});
});
第二OK按鈕我怎麼能轉換成一個數組呢?數據插入到表格中,但它插入僅選中或突出顯示的行項目,而不插入其他行項目。該行有類,當你點擊它時突出顯示該行。
case "Add":
if(isset($_POST['Add'])){
$Addquery = "INSERT INTO tb_empgrocery (empgrocID, coopmemID , date_ordered, item_no, qty_ordered, unit_price, amount, date_delivered, qty_delivered, order_status, released_by) VALUES ('".$_POST['empgrocID']."', '".$login['is_coopmemID_kiosk']."', (NOW()), '".$_POST['itemNo']."', '".$_POST['orderqty']."', '".$_POST['unit_price']."', '".$_POST['amount']."', '".$_POST['date_delivered']."', '".$_POST['qty_delivered']."','".$_POST['order_status']."','".$_POST['released_by']."')";
mysql_query($Addquery, $con);
}
break;
這是正確的嗎?
case "Add":
$_POST = array_map('addlashes', $_POST);
$values = array();
foreach ($_POST as $key => $value) {
$values[] = "('{$_POST['empgrocID']}', '{$login['is_coopmemID_kiosk']}', '{$_POST['(NOW())']}', '{$_POST['itemNo']}', '{$_POST['orderqty']}', '{$_POST['unit_price']}', '{$_POST['amount']}', '{$_POST['date_delivered']}', '{$_POST['qty_delivered']}', '{$_POST['order_status']}', '{$_POST['released_by']}')";
}
if(sizeof($values)) {
$query = "INSERT INTO tb_empgrocery (empgrocID, coopmemID , date_ordered, item_no, qty_ordered, unit_price, amount, date_delivered, qty_delivered, order_status, released_by) VALUES ".implode(',', $values);
$result = mysql_query($query, $con);
}
break;
在此先感謝
請幫忙謝謝 – Micaela
Heeeeeeeeeeeeeelp – Micaela