Reputation: 65
My problem here is the pullout_qty
table column did not update while the description and date_requested
were updated.
function update_save() {
var cnt = parseInt($('#tblBB_rows_cnt').val());
var description = $('#form_description').val();
var status = $('#stat_filter').val();
var qty = [];
var z = 0;
for (var x = 0; x < cnt; x++) {
if ($('#tblC_visibility' + x).val() == 1) {
qty[z] = $('#tblC_qty' + x).val();
z += 1;
}
}
$.ajax({
url: URL + "index.php/pullout_request/loadEditSave",
method: "POST",
data: {
qty: qty,
description: description,
status: status
},
success: function(data) {
SYS_pending_setlist();
setTimeout(function() {
$("#dialog1").dialog("close");
}, 500);
},
error: function(err) {
console.log(err);
}
});
}
There were two separate tables here, across_pullout
and across_pullout_items
. When I update it only the across_pullout
was updated. The pullout_qty
in across_pullout_items
becomes 0 (output)
$pullout_qty=$_POST['qty'];
$status=$_POST['status'];
$date_requested=date("Y-m-d H:i:s");
$description=$this->db->escape_str($_POST['description']);
$sql .= "UPDATE `across_pullout` SET date_requested='$date_requested', `description`='$description' where status='0' and remark='1';";
$sql.= "UPDATE across_pullout_items set pullout_qty='$pullout_qty' where remark='1';";
?>
Upvotes: 1
Views: 221
Reputation: 1081
Make me correct if I am not wrong. In Codeigniter, You can't update multiple tables with one SQL statement. Codeigniter does allow you to use transactions though. like below
$this->db->trans_start();
$this->db->query('AN SQL QUERY...');
$this->db->query('ANOTHER QUERY...');
$this->db->query('AND YET ANOTHER QUERY...');
$this->db->trans_complete();
Here are the complete documents for this Transactions please check it out... which will also help you to run both queries together, Advantage of using transaction it will only insert data when both query return success...
Upvotes: 2