'How to compare two SQL database table and mark checkbox based on result using php
Hope you are doing great. So I am working on a automated attendance system using face recognition and I am displaying data through php. I have a SQL database with the name of student_db and there are two tables in it with the name of mark_attendance and student_detail. Face recognition system recgnize faces and send rollnumber and date on mark_attendance
where as student_detail consist of whole class students name and rollnumber.enter image description here enter image description here
I am displaying name, rollnumber and a checkbox on frontend what I want to do is to mark checkbox aUtomatically if student is present. It should compare data of mark_attendance table with the studet_detail table and mark checkbox.
I AM ATTACHING THE CODE I HAVE TRIED BUT ITS NOT WORKING.
<html>
<head></head>
<body>
<table border="1">
<tr>
<th> Name </th>
<th> Attendance </th>
</tr>
<?PHP
include('db_connection.php');
$qry = "SELECT * FROM student_detail";
$result = mysqli_query($db_con, $qry);
$ftch = mysqli_fetch_assoc($result);
$markattendance = "SELECT * FROM mark_attendance ";
$ma = mysqli_query($db_con, $markattendance);
if(mysqli_num_rows($result) > 0)
{
foreach($result as $r)
{
$sav = "SELECT * FROM mark_attendance t1
JOIN student_detail t2
ON t2.rollno = t1.rollno";
$sa = mysqli_query($db_con, $sav);
$s = mysqli_fetch_assoc($sa);
$count = mysqli_num_rows($sa); echo "</b>";
echo "<table><tr>";
echo "<td>".$r['Name']."</td>";
// echo $r['rollno'];
echo $s['rollno'];
if($count >= 1 && $s['rollno'] == $r['rollno']){
echo "<form><td> <input type='checkbox' checked value=".$r['Name']."></td>";
}
else{
echo "<form><td> <input type='checkbox' value=".$r['Name']."></td>";
}
// echo "<form><td> <input type='checkbox' value=".$r['Name']."></td>";
// echo "<td> <input type='text' value=".$r['rollno']."></td></form>";
echo "</tr>";
}
}
?>
</table>
</body>
</html>
Its MARKING only the first data checkbox on db not other after it.
I also have tried with while loop and other stuff but its still not working can you run it on your computer and provide me the working code.
SORRY FOR THE BAD ENGLISH
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
