![]() |
How do i insert multiple selected checkboxes into the database - 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: How do i insert multiple selected checkboxes into the database (/showthread.php?tid=58722) |
How do i insert multiple selected checkboxes into the database - El Forum - 07-12-2013 [eluser]itz4mesays[/eluser] I am trying to insert multiples values from selected checkboxes into the database and i can only insert one out of it. Tried your using insert_batch() but not getting it. I think i get the array properly. Can anyone please help me out? Thanks for your swift response and time to stop by to read this post. My View if(isset($select) && count($select)){ echo '<table border="1" cellspacing="0" cellpadding="3">'; //$data=array('onsubmit'=>'return confirmdelete()'); echo form_open('student/add_courses'); //echo"<form method='post' name='form' id='form' acti confirmdelete();'>"; echo '<tr valign="top">'; echo "<th width='50' align='center'><input id='delete' type='submit' name='delete' value='x'/></th>"; echo '<th>Course Code</th>'; echo '<th>Course Title</th>'; echo '<th>Course Unit</th>'; echo '<th>Course Status</th>'; echo '<th>Level</th>'; echo '<th>Semester</th>'; echo '</tr>'; foreach ($select as $key => $row) { echo '<tr valign="top">'; echo '<td align="center"><input type="checkbox" name="checkbox[]" id="checkbox[]" value='.$row['id'].'></td>'; echo '<td align="center">'.$row['course_code'].'</td>'; echo '<td align="center">'.$row['course_title'].'</td>'; echo '<td align="center">'.$row['course_unit'].'</td>'; echo '<td align="center">'.$row['course_status'].'</td>'; echo '<td align="center">'.$row['level'].'</td>'; echo '<td align="center">'.$row['semester'].'</td>'; echo '</tr>'; //echo $row['id']; } echo '</table>'; echo"</form>"; How do i insert multiple selected checkboxes into the database - El Forum - 07-12-2013 [eluser]PravinS[/eluser] when you will post the form, you will get "checkbox[]" values in array, so according to its number of element you can insert records in database first check the "checkbox[]" values by print_r('checkbox') How do i insert multiple selected checkboxes into the database - El Forum - 07-12-2013 [eluser]itz4mesays[/eluser] I got Array ( [0] => 110 [1] => 109 [2] => 108 [3] => 107 [4] => 106 ) when i used the print_r() but i want to be able to post the other fields alongside with the id to another table. Two tables are involved: i. courses - This contains the courses that are added ii. studcourses - contains courses that are added from the courses table. Please i need your help. Thanks |