Hello every one,
Currently I am using this update query
$upd2 = "UPDATE warehouse_feedback set final_status = 'DELIVERED', updated_on = '".$sel_res[$i]['receipt_delivery']."' where order_id = '".$sel_res[$i]['order_id']."' and tracking_id = '".$sel_res[$i]['tracking_id']."'";
$this->model->exec($upd2);
But I would like to use inbuilt update function . How to use this query with that function ? or Can you please suggest Custom update function like for the above requirement ? like by passing multiple values in where clause.
Siri
Thanks in advance
How to use Custom update query by using inbuilt update function
4 years ago
4 years ago
#1
4 years ago
#2
Hello,
https://trongate.io/docs_m/information/the-update-method
In order for this to work you need to get the update_id of the record you are updating.
So, I assume from this query you can get the update_id.
$update_id = Query update_id;
Then set the $data['variables to update']
And run the update method
***Important***
This assumes that you are in the Warehouse_Feedback controller.
If not then use 1 more line below to set the module
$data['final_status'] = 'DELIVERED';
$data['update_on'] = $sel_res[$i]['receipt_delivery'];
$this->module->('warehouse_feedback');
$this->model->update($update_id, $data, 'warehouse_feedback');
****This may help you****DEBUG MODE
https://trongate.io/docs_m/information/how-to-use-debug-mode
Hope this helps,
Dan
https://trongate.io/docs_m/information/the-update-method
In order for this to work you need to get the update_id of the record you are updating.
So, I assume from this query you can get the update_id.
$update_id = Query update_id;
Then set the $data['variables to update']
And run the update method
***Important***
This assumes that you are in the Warehouse_Feedback controller.
If not then use 1 more line below to set the module
$data['final_status'] = 'DELIVERED';
$data['update_on'] = $sel_res[$i]['receipt_delivery'];
$this->module->('warehouse_feedback');
$this->model->update($update_id, $data, 'warehouse_feedback');
****This may help you****DEBUG MODE
https://trongate.io/docs_m/information/how-to-use-debug-mode
Hope this helps,
Dan
4 years ago
#3
Hi,
Thanks for the reply. As you said I can get the update id from query. But there is a possibility of duplicate tracking ids for the order id. Means I will have multiple duplicate order ids and multiple duplicate tracking ids. So If i update based on the primary key then I need to run updated query multiple times. So Instead that, If i run this query like set status = 'DELIVERED' where order_id = 'order_id' and tracking_id = 'tracking_id'
then this one query will update all the related order id and tracking ids status.
Any Ideas/ suggestions?
Thanks for the reply. As you said I can get the update id from query. But there is a possibility of duplicate tracking ids for the order id. Means I will have multiple duplicate order ids and multiple duplicate tracking ids. So If i update based on the primary key then I need to run updated query multiple times. So Instead that, If i run this query like set status = 'DELIVERED' where order_id = 'order_id' and tracking_id = 'tracking_id'
then this one query will update all the related order id and tracking ids status.
Any Ideas/ suggestions?
4 years ago
#4
Ok,
So is it like this
One Customer has many Order id's and One Order has many Tracking id's?
So is it like this
One Customer has many Order id's and One Order has many Tracking id's?
4 years ago
#5
Hi,
Correct, but in warehouse feedback table we have only order ids and related tracking info
Correct, but in warehouse feedback table we have only order ids and related tracking info
4 years ago
#6
Does the query above work as you want?
4 years ago
#7
Yes , please
4 years ago
#8
Okay here goes. UPDATED
Do you know how to set the Model Debug to true?
Is so do that to see how the query looks.
Test this out. No Promises it will work.
If debug is set you can verify the query is what you are looking for.
$data['final_status'] = 'DELIVERED';
$data['updated_on'] = $sel_res[$i]['receipt_delivery'];
$order_id = $sel_res[$i]['order_id'];
$tracking_id = $sel_res[$i]['tracking_id'];
$this->model->order_tracking_update($order_id, $tracking_id $data, 'warehouse_feedback');
private function order_tracking_update($order_id, $tracking_id $data, $target_tbl=NULL) {
if (!isset($target_tbl)) {
$target_tbl = $this->get_table_from_url();
}
$sql = "UPDATE `$target_tbl` SET ";
foreach ($data as $key => $value) {
$sql.= "`$key` = :$key, ";
}
$sql = rtrim($sql, ', ');
$sql.= " WHERE `$target_tbl`.`order_id` = :order_id AND `$target_tbl`.`tracking_id` = :tracking_id";
$data['id'] = $update_id;
$data = $data;
if ($this->debug == true) {
$query_to_execute = $this->show_query($sql, $data, $this->query_caveat);
}
$this->prepare_and_execute($sql, $data);
}
Do you know how to set the Model Debug to true?
Is so do that to see how the query looks.
Test this out. No Promises it will work.
If debug is set you can verify the query is what you are looking for.
$data['final_status'] = 'DELIVERED';
$data['updated_on'] = $sel_res[$i]['receipt_delivery'];
$order_id = $sel_res[$i]['order_id'];
$tracking_id = $sel_res[$i]['tracking_id'];
$this->model->order_tracking_update($order_id, $tracking_id $data, 'warehouse_feedback');
private function order_tracking_update($order_id, $tracking_id $data, $target_tbl=NULL) {
if (!isset($target_tbl)) {
$target_tbl = $this->get_table_from_url();
}
$sql = "UPDATE `$target_tbl` SET ";
foreach ($data as $key => $value) {
$sql.= "`$key` = :$key, ";
}
$sql = rtrim($sql, ', ');
$sql.= " WHERE `$target_tbl`.`order_id` = :order_id AND `$target_tbl`.`tracking_id` = :tracking_id";
$data['id'] = $update_id;
$data = $data;
if ($this->debug == true) {
$query_to_execute = $this->show_query($sql, $data, $this->query_caveat);
}
$this->prepare_and_execute($sql, $data);
}
4 years ago
#9
Hi thank you
Just this was missed
I will let you know. Hope this will work
Just this was missed
I will let you know. Hope this will work
4 years ago
#10
Hi,
tested and did some modifications. The working one
controller
Model
tested and did some modifications. The working one
controller
Model