SELECT selected CHECKBOX and update in selected row into DATABASE in Codeigniter |
i am new in CI,when i update this i did not get id, Please help me when i click on submit i got the id = 0, So please help me, i want update selected check box checked and update that record in Database
here is my VIEW: <form method="POST" action="<?php echo base_url() . "welcome/user_manager/" ?>"> <label>Select User</label> <select name="user_role" id="user_role" onchange="calculate(this)"> <option>--Select User--</option> <?php foreach ($roll_get as $roll) { ?> <option value="<?php echo $roll->user_id; ?>" id="<?php echo $roll->user_id; ?>"><?php echo $roll->full_name; ?></option> <?php } ?> </select><br> <input id="checkAll" type="button" value="Check All"> <div class="button"> <?php foreach ($listMenuLevel1 as $menu1) { ?> <div id="checkboxlist"> <li class="treeview"> <input type="checkbox" name="sample[]" value="0"/> <a href="<?php echo base_url(); ?>welcome"> <span><?php echo $menu1->category_name; ?></span> </a> <?php if (count($this->main_model->listchildMenus($menu1->category_id)) > 0) { ?> <ul class="treeview-menu"> <?php foreach ($this->main_model->listchildMenus($menu1->category_id) as $menu2) { ?> <li ><input type="checkbox" name="sample[]" value="0"/><a href="<?php echo base_url(); ?><?php echo $menu2->category_link; ?>"><?php echo $menu2->category_name; ?></a></li> <ul> <?php foreach ($this->main_model->listchildMenus($menu2->category_id) as $menu3) { ?> <li><input type="checkbox" name="sample[]" value="0"/><a href="<?php echo base_url(); ?><?php echo $menu3->category_link; ?>"><?php echo $menu3->category_name; ?></a></li> <?php } ?> </ul> <?php } ?> </ul> <?php } ?> </li> </div> <?php } ?> <input type="submit" class="btn btn-primary" value="Save"> </form> Here Is My Controller: public function user_manager() { $user_id = $this->input->post('user_role'); $this->main_model->check_update($user_id); } Here is My Model: public function check_update($user_id){ $data = array(); if($this->input->post('sample')){ $ans = $this->input->post('sample'); foreach($ans as $each){ if(isset($each) && $each != ""){ $data['user_rights'] = '1'; $this->db->where('user_id', $each)->update('user_registration', $data); } } } } Code: <input type="checkbox" name="sample[]" value="0"/> You've hardcoded sample variable values to 0. You should update these to what-ever values you need to come back from the form.
(07-19-2018, 12:30 AM)Pertti Wrote: I want fix value when i am update that value=0 is static but i did not get row id, when i am update this code then value="0" consider as a id so i am confused how to get particular row id
Am I right in thinking what you want to do is save keep records in user_registration that crossreference user IDs and category IDs?
Radio buttons and check boxes will be empty if not set/checked
PHP Code: $checked_value = isset($this->post('your_checkbox_name')) ? 1 : 0; What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |