0

I have made attendance sheet containing student's roll no, name,present and absent dynamically retrieved from database.

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$course=$_GET['id'];
mysql_select_db('attendance');


 $sql = "SELECT student.sr_no, student.roll_no, student.name , mark_attendance.percentage FROM  student INNER JOIN mark_attendance ON mark_attendance.roll_no = student.roll_no     WHERE student.course_name Like '$course' ORDER BY roll_no ASC";


 $retval = mysql_query( $sql, $conn );
 if(! $retval )
 {
 die('Could not get data: ' . mysql_error());
 }

while($row = mysql_fetch_array($retval, MYSQL_NUM))
{

print "<tr>"; 
print "<td>" . $row[0] . "</td>"; 
print "<td>" . $row[1] . "</td>"; 

 print "<td>" . $row[2] . "</td>";

 echo "<td>" .  '<input type="checkbox" name="present[]" value= "1"   />'.  "   </td>";//checkboxes for present
  echo "<td>" .    '<input type="checkbox" name="present[]" value= "0"  />'  . "</td>";//checkboxes for absent
  print "<td>" . $row[3] . "</td>";




   echo "<td>" . '<input type="text" name="remarks" value= ""  />' .  "</td>";
   print "</tr>"; 
  }

   }



   mysql_free_result($retval);

   mysql_close($conn);
    ?>

I want to make these two checkbox lists mutually exclusive means when I click on Present checkbox, its corresponding absent checkbox becomes empty and vice virsa.

  • 1
    Don't use the deprecated MySQL extension anymore! Switch to prepared statements using MySQLi or PDO. – ComFreek Oct 30 '13 at 09:27

2 Answers2

1

Use radio buttons instead

// radio button for present
echo '<td><label><input type="radio" name="present[' . $row[0] . ']" value="1"> present</label></td>';
// radio button for absent
echo '<td><label><input type="radio" name="present[' . $row[0] . ']" value="0"> absent</label></td>';
TiMESPLiNTER
  • 5,741
  • 2
  • 28
  • 64