I have the following records in my table:
id status
129 'Ready'
129 'Ready'
129 'Confirm'
129 'Confirm'
129 'Processing'
130 'Confirm'
What I am trying to change is change the status according to id based on user input.
I am capturing user input in my controller as below:
$id= $this->input->post("id");
$confirm = $this->input->post("confirm");
$processing = $this->input->post("processing");
$ready = $this->input->post("ready");
$delivered = $this->input->post("delivered");
an example of user input values is as follows:
$id= 129
$confirm = 1
$processing = 2
$ready = 2
$delivered = 0
This basically means that all rows with id 129 should have status in the order, confirm should appear once, processing twice, ready ready and no delivered.
How can I update the status so that it would be like below using the above input data:
id status
129 'Ready'
129 'Ready'
129 'Confirm'
129 'Processing'
129 'Processing'
130 'Confirm'
In my model I tried as below but it's not working.
public function update_status($serialized,$confirm,$processing,$ready,$delivered) {
$data = array(
'status' => 'Confirm',
);
$this->db->where('is_serialized', $serialized);
$this->db->limit($confirm);
$this->db->update('items', $data);`$data = array(
'status' => 'Processing',
);
$this->db->where('is_serialized', $serialized);
$this->db->limit($processing);
$this->db->update('items', $data);
$data = array(
'status' => 'Ready',
);
$this->db->where('is_serialized', $serialized);
$this->db->limit($ready);
$this->db->update('items', $data);
$data = array(
'status' => 'Delivered',
);
$this->db->where('is_serialized', $serialized);
$this->db->limit($delivered);
return $this->db->update('items', $data); }
Any help would be highly appreciated.
`
$this->db->where('status', 'Ready'); $this->db->update('table', array('status' => 'Processing');however I wouldn't suggest using strings and instead use number codes 1, confirm; 2, ready; .etc. and define those codes according to their string values in a separate table. I still don't think this is the most efficient/right way to do this because if user wants to change one row, you don't have a unique column (?) so your left doing less than efficient methods.129and statusreadyto change. doesn't this matter? or do you just want to arbitrarily choose a row with id129and statusreadyand change its value.