Welcome Guest, Not a member yet? Register   Sign In
saving multiple checkbox in the database
#1

[eluser]rajneeshgobin[/eluser]
this is my first codeigniter work here is the situation

i wish something like this but with many more check boxes about 100 probably,

the senario ls like this
there will be many users in a system,
each user profile will have these kind of questions

for example

Hobby :
tenis []
badminton[]
footbal[]
carrom[]

programming language :
perl[]
python[]
cobol[]
as3[]

favorit biscuit :
bakers[]
subana[]
ect[]


ect ect

these checkbox need to reflect for diferent users.
administrator can add new category [ ie hobby , programming language]
under each category he can add more options such as football, tenis ect

he should be able to have an interface to modify the options entered by user when a user request a change


what is a good way to implement this in php mysql

here is what i was able to do so far...

view
Code:
<?php echo form_open('usersctrl/data_submit/'); ?>
      <table width="485" cellspacing="0" cellpadding="0">
        <tr>
          <td width="85">
          </td>
          <td width="200" colspan="2">
            
  </td>
  </tr>
  <tr>
    <td>
      users type:
    </td>
    <td>
      &lt;input name="username" value="
&lt;?php echo set_value('username'); ?&gt;
" type="text" /&gt;
  </td>
  <td>
    &lt;?php echo form_error('users data'); ?&gt;
  </td>
  </tr>
  <tr>
    <td>
      test field:
    </td>
    <td>
      &lt;input name="password" value="
&lt;?php echo set_value('password'); ?&gt;
" type="text" /&gt;
  </td>
  <td>
    &lt;?php echo form_error('date'); ?&gt;
  </td>
  </tr>
  <tr>
    <td width="223">
      &nbsp;
    </td>
    <td>
      &lt;input name="add" type="submit" value="add" alt="add" /&gt;
    </td>
  </tr>
      </table>
   <table >
&lt;?php foreach ($query_platform as $row): { ?&gt;
<tr>
    <th>&lt;?php echo $row['categoryName'];?&gt;</th>

</tr>    


&lt;?php foreach ($query_option as $row_options): { if($row_options['subcategory_id']==$row['id']) {?&gt;
<tr>
    <td>&lt;?php echo $row_options['subcategory_name'];?&gt;</td>
    <td>&lt;input type="checkbox" name="" value=""&gt;&lt;/input></td>


</tr>    
&lt;?php }} ?&gt;
&lt;?php endforeach; ?&gt;
&lt;?php } ?&gt;
&lt;?php endforeach; ?&gt;
</table>
  
      &lt;?php echo form_close(); ?&gt;

category model

Code:
function allCategory()
    {
        
        $this->db->select('id');
        $this->db->select('CategoryName');
        $this->db->from('categorytable');
        
        
        $query = $this->db->get();
        
        
        if ($query->num_rows() > 0) {
            foreach ($query->result_array() as $row) {
                $data_room_type[] = $row;
            }
        }
        
        return $data;
    }


subcategorymodel

Code:
function allOptions()
    {
        $this->db->select('id');
        $this->db->select('subcategory_name');
        $this->db->select('subcategory_id');
        $this->db->from('subcategory');
                
        $query = $this->db->get();
        
        
        if ($query->num_rows() > 0) {
            foreach ($query->result_array() as $row) {
                $data[] = $row;
            }
        }        
        return $data;
    }

user controller

Code:
public function add_users()
    {

//$data['user_id'] = $this->users_model->get_user_id_from_username($this->session->userdata('username'));


foreach ($this->users_model->get_user_id_from_username($this->session->userdata('username')) as $row)
{
$config = array('userID' => $row->id);
} //$config = array('userID' => $this->session->userdata('username'));
$this->load->library('acl', $config);


    $this->load->model('category_model');    
    $this->load->model('subcategory_model');    
  
    $data['query_platform'] = $this->platform_model->allCategory();
    $data['query_option'] = $this->options_model->allOptions();




        $this->load->view("site_header");
        $this->load->view("site_nav");
        $this->load->view("admin/users/users_add",$data);
        $this->load->view("site_footer");
    }

below is a screenshot of what i got so far,

now i wish to be able to save these sub category options to database when we click save user here. how can i save all these data and is the above method good so far?


Messages In This Thread
saving multiple checkbox in the database - by El Forum - 09-17-2014, 11:11 PM
saving multiple checkbox in the database - by El Forum - 09-17-2014, 11:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB