I have a table that contains rows of user orders, I would like the user to be able to update multi orders rows in one click, so I am using a checkbox so the user can check the order that would like to update.
each checkbox represents the order id that has to be updated if checked, I tried to use loops, but the code else cause an error, or do nothing.
here is the my model code:
public function update_order(){
$data = array(
'status' => 'Pack'
);
$this->db->where('order_id', $this->input->post('checkbox'));
return $this->db->update('user_orders', $data);
}
Controller code (I placed the code without any loops just to make it more clear):
public function update_order()
{
$this->user_model->update_order();
}
and finally here is the view:
<?php echo form_open('user/update_order'); ?>
<?php foreach ($users as $user): ?>
<input type="checkbox" class="custom-control-input" name="checkbox" value="<?php echo $user['order_id']; ?>">
<?php endforeach; ?>
<button type="submit" class="btn btn-sm btn-block btn-warning text-white">Update</button>
</form>