jowy jowy - 5 days ago 6
MySQL Question

I want to save all the checkbox values I select

I m trying to store checkbox value subject_id but when i store this value to database it just store the last selected checkbox inside the database... please help me to sort out the code so I can get all selected values.

I want to save all the checkbox values I selected,but if I check more then one checkbox it always save the last checkbox.

function get_class_section($day='',$section='',$class='')
{

print_r($section);
$sections = $this->db->get_where('class_routine' , array(
'day' => $day,'section_id'=>$section,'class_id'=>$class
))->result_array();


foreach ($sections as $row) {


echo "<table class=\"table table-bordered datatable\" id=\"table_export\" >";

echo "<thead>";
echo "<th>Subject</th><th colspan=\"2\">status</th>";
echo "</thead>";

echo "<tbody>";
echo "<tr>";

echo "<td>". $this->crud_model->get_subject_name_by_id($row['subject_id'],"<input type=\"text\" name=\"subject_id\" value=\"subject_id\" >");
echo "<input type=\"checkbox\" name=\"types[]\" value=\"".$row['subject_id']."\" set_checkbox('types[]', 'subject_id')>";

echo "</td>";

echo "<td>present&nbsp;&nbsp;<input type=\"checkbox\" value=\"1\" ></td>"
. "<td>Absent&nbsp;&nbsp;<input type=\"checkbox\" name=\"types[]\" value=\"0\"></td>";



echo "</tr>";
echo "</tbody>";

echo "</table>";




}

}


how to save all the check-boxes that i selected

Answer

You need foreach loop to get all checked checkboxes

Try This:

if(isset($_REQUEST['types']) && $_REQUEST['types']!=array())
{
  foreach ($_REQUEST['types'] as $key => $value) {

   // in $value,you will get checkbox value

  }
}
Comments