I am a self learner but I am stuck here. I hope you guys can help me out of this. Department value is different every time and I want to insert the value to mysql database. I don't know how to do it. But I did the following to get this done.
<tr>
<td>
<?php echo $result['dep']; ?><input type="hidden" name="department" value="<?php echo $result['dep']; ?>">
</td>
<td>
<input type="radio" name="attendance[<?php echo $result['roll'] ?>]" required="1" value="present"> Present
<input type="radio" name="attendance[<?php echo $result['roll'] ?>]" required="1" value="absent"> Absent
</td>
</tr>
And here is my iteration code to insert the form data to mysql database:
if(isset($_POST['submit'])){
$attendance = $_POST['attendance'];
$dep = $_POST['department'];
$current_date = date('Y-m-d');
$getAttendance = $user->insertAttendance($dep, $attendance, $current_date);
}
Here is the insert function: public function insertAttendance($dep, $attendance = array(), $date){ foreach ($attendance as $att_key => $att_value) {
$sql = "INSERT INTO tcr_attendance (roll, department, attendance, attendance_date) VALUES ('$att_key', '$dep', '$att_value', '$date')";
$insert_row = $this->db->insert($sql);
}
But all I get is first value for the department. Please, someone help me out of to get iteration for department values inside the foreach loop for attencance.