Update Multiple checkbox if it checked or not |
I have a form with a list of the details of products (checkbox, id, name, price...). Now I want to be able to update the price of the products where the checkbox is checked with a percentage, given by the user on a button click.
Currently I am stuck on retrieving the data of the checked checkboxes and updating the data if the checkbox is checked. Model (tried something, but it's not working properly public function update__all($id, $price) { $this->db->set('price', 'price *'. ((100 + $price)/100) .'',false); $this->db->where("id", $id ) $this->db->update(self::TABLE_NAME1); return $this->db->affected_rows(); } This is my view <tr> <td class="px-6 py-4 whitespace-nowrap text-xs font-medium text-gray-900"> <input id="price_check" name="price_check" type="checkbox" value="1" <?php echo set_checkbox('price_check', '1'); ?> class="rounded focus:ring-blue-500 h-4 w-4 text-blue-600 border-gray-300"> </td> <td class="px-3 py-4 whitespace-nowrap text-xs font-medium text-gray-900"> <input type="hidden"name="id" id="id" value="<?=$motor->id?>"> <?=$motor->product_id?> </td> <td class="px-3 py-4 whitespace-nowrap text-xs font-medium text-gray-900"> <input type="hidden"name="motortype" id="motortype" value="<?=$motor->type_motor?>"><?=$motor->type_motor?> </td> <td class="px-3 py-4 whitespace-nowrap text-xs font-medium text-gray-900"> <?php if($this->session->userdata('admin') == 0):?> <input type="number" step="0.01" name="price" id="price" value="<?= set_value('price', $motor->price ?? null) ?>" class="max-w-lg block shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:max-w-xs sm:text-xs border-gray-300 rounded-md"> <?php else:?> <?=$fmt->formatCurrency($motor->price, "EUR") ?> <?php endif?> </td> <?php if($this->session->userdata('admin') == 0):?> <td class="px-3 py-4 whitespace-nowrap text-xs font-medium text-gray-900"> <?= date_format(new DateTime($motor->modified_on),"Y-m-d") ?? "nvt" ?> </td> <td class="px-3 py-4 whitespace-nowrap text-left text-xs text-gray-500 px-3 py-3"> <button type="submit" class="inline-flex items-center px-5 py-2 border border-transparent text-sm leading-4 font-medium rounded-md shadow-sm text-white bg-blue-600 hover:bg-blue-700 echatspin echatrandom focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500"> Aanpassen </button> </td> <?php endif?> </tr> Thanks in advance
cant tell you for checkbox but the logic (at least for CI4.2.6) is similar to choice from a drop down.
the way I do update is to get current data from a database and populate it into a form, if there is text to update. IN a form I also have a drop down Code: <select id="category" name="category"> in a controller i get choice by user: Code: $category= $this->request->getVar('category'); I then use that to update db. checkbox and updating is going to be similar. |
Welcome Guest, Not a member yet? Register Sign In |