CodeIgniter Forums
Save List Box Values in Many Tables - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Save List Box Values in Many Tables (/showthread.php?tid=33492)



Save List Box Values in Many Tables - El Forum - 08-27-2010

[eluser]shahmy[/eluser]
Hi, I have 2 list boxes in my view. I am moving selected list box values from left to right,
I want to know, "how to save the right list box values in table ?". If any one know, Please help me.
Thank You.


Save List Box Values in Many Tables - El Forum - 08-28-2010

[eluser]Derdiusz[/eluser]
Name your list box "as array" like:
Code:
<select name="right_side[]" multiple>
...
</select>
after posting your form (ie. with method="POST") you have $_POST['right_side'] which is an array with values from select. You can do:

Code:
foreach($_POST['right_side'] as $v)
{
$this->db->insert('your_table', array('right_value'=>$v));
}


Of course this is a sample code. right_value from insert query is a field in your database table.

Greetings
D.


Save List Box Values in Many Tables - El Forum - 08-29-2010

[eluser]shahmy[/eluser]
Hi Derdiusz, I was try what u post above. But the values not inserted in tables, i will copy my codes bellow, that is when i post the form the null values return to the model.
If u know please help me.

"My view"

Code:
&lt;?php echo form_open_multipart('teachers/videomatrials/insertmatrials',$frmname);?&gt;
<select multiple name="destination_stu[]"  size="4">
  </select>
&lt;input type="submit" value="Add"/&gt;
&lt;?php echo form_close();?&gt;

"My Model"

Code:
foreach($_POST['destination_stu'] as $stu_id)
                {
                    $this->db->insert('stu_to_sub', array('stu_id'=>$stu_id,
                    'sub_id'=>$sub_id,
                    ));
                
                                
                
                    $this->db->insert('stu_to_mod',array(
                    'stu_id'=>$stu_id,
                    'mod_id'=>$mod_id,
                    ));
                
                                
                
                    $this->db->insert('tech_to_stu',array(
                    'stu_id'=>$stu_id,
                    'tech_id'=>$this->session->userdata('tech_id'),
                    ));
                
                }

Thank You.