Welcome Guest, Not a member yet? Register   Sign In
SELECT selected CHECKBOX and update in selected row into DATABASE in Codeigniter
#1

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);
                }
            }
        }
    }
Reply
#2

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.
Reply
#3

(07-19-2018, 12:30 AM)Pertti Wrote:
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.

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
Reply
#4

Am I right in thinking what you want to do is save keep records in user_registration that crossreference user IDs and category IDs?
Reply
#5

(07-19-2018, 01:31 AM)Pertti Wrote: Am I right in thinking what you want to do is save keep records in user_registration that crossreference user IDs and category IDs?

yes exactly correct. i want save that record in user registration table
Reply
#6

Radio buttons and check boxes will be empty if not set/checked

PHP Code:
$checked_value = isset($this->post('your_checkbox_name')) ? 0
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

(07-19-2018, 08:44 AM)InsiteFX Wrote: Radio buttons and check boxes will be empty if not set/checked

PHP Code:
$checked_value = isset($this->post('your_checkbox_name')) ? 0

Thank You so much
Reply




Theme © iAndrew 2016 - Forum software by © MyBB