这是我为表添加查询数组(tb_empgrocery),这可以正常工作
case "Add":
$itemno = $_POST['itemno'];
$qty = $_POST['qty'];
$unitprc = $_POST['unitprc'];
$amt = $_POST['amt'];
$coopmemid = $_SESSION['kiosk']['is_coopmemID_kiosk'];
for($x=0; $x<count($itemno); $x++) {
$Addquery = "INSERT INTO tb_empgrocery (coopmemID , date_ordered, item_no, qty_ordered, unit_price, amount)
VALUES ('$coopmemid',(NOW()),'$itemno[$x]','$qty[$x]','$unitprc[$x]','$amt[$x]')";
mysql_query($Addquery, $con);
}
break;
这是我对表的保存查询(tb_empgroc_master),这不会将任何数据保存到表中。此表有很多列,但我只放data_ordered
因为它设置为timestamp
而其他列没有值。我试图在表中至少有一个行数据,这是要显示的date_ordered的值。
case "Save":
if(isset($_POST['Save'])){
$Savequery = "INSERT INTO tb_empgroc_master (date_ordered) VALUES ((NOW()))";
mysql_query($Savequery, $con);
}
break;
这是添加查询的循环数组函数
function saveme(){
var data = new Array();
$('#cLoanOut2 > tbody > tr').each(function() {
var nodes = $(this).children();
var itemno = nodes[0].innerHTML,
qty = nodes[2].innerHTML,
unitprc = nodes[3].innerHTML,
amt = nodes[4].innerHTML;
data.push({
name: "itemno[]",
value: itemno
},{
name: "qty[]",
value: qty
},{
name: "unitprc[]",
value: unitprc
},{
name: "amt[]",
value: amt
});
});
return data;
}
这是我调用2个查询的ajax请求
$('#OKBtn2').click(function(){
$('#myModal2').modal('hide');
var itemid = $('#main-form2 .active').attr('id'),
qty = $('#main-form2 #'+itemid+' td:eq(2)').text(),
unit_price = $('#main-form2 #'+itemid+' td:eq(3)').text(),
amount = $('#main-form2 #'+itemid+' td:eq(4)').text();
bootbox.confirm("Are you sure?","No","Yes",function(r){
if(r) {
var data = saveme();
data.push({
name: "todo",
value: "Add"
});
console.log(data);
$.ajax({
url : url,
type : "POST",
async : false,
data : data, --->//This calls the first query which is Add query and it push the data array and it works for the table (tb_empgrocery)
todo: "Save", --->//Is this right to call the Save query? Because this doesn't work for the table (tb_empgroc_master)
success:function(result){
bootbox.alert('Ordered',function(){
});
updateTable();
}
});
} else {
}
});
});
如何在第一个查询之后调用第二个查询?在此先感谢:))
答案 0 :(得分:0)
根据Jquery的说法,没有todo选项。 see me
你需要重构你的功能。提取ajax函数并使用不同的输入参数两次。
代码将是这样的。我没有测试它。
0 + !!$var ( !! true => 1, !! false => "" )
1 - !$var
$var ? 1 : 0
});
答案 1 :(得分:0)
现在我知道了答案..感谢帮助家伙 在我的PHP中
Application.EnableEvents = True
在javascript中
case "Add":
$itemno = $_POST['itemno'];
$qty = $_POST['qty'];
$unitprc = $_POST['unitprc'];
$amt = $_POST['amt'];
$coopmemid = $_SESSION['kiosk']['is_coopmemID_kiosk'];
for($x=0; $x<count($itemno); $x++) {
$Addquery = "INSERT INTO tb_empgrocery (coopmemID , date_ordered, item_no, qty_ordered, unit_price, amount)
VALUES ('$coopmemid',(NOW()),'$itemno[$x]','$qty[$x]','$unitprc[$x]','$amt[$x]')";
mysql_query($Addquery, $con);
}
$Savequery = "INSERT INTO tb_empgroc_master (date_ordered) VALUES ((NOW()))";
mysql_query($Savequery, $con);
break;