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 |
Messages In This Thread |
Update Multiple checkbox if it checked or not - by MurbiesWalto - 10-07-2022, 04:36 AM
RE: Update Multiple checkbox if it checked or not - by captain-sensible - 10-08-2022, 03:13 AM
|