Hi first time posting here. I'm trying to display the list of attendance for specific students upon parent log in. I have the db tables of both student and parent connected by the student ID (I ask for the student ID upon parent registration). Ex:
Student | Parent |
---|---|
sid | pid |
Student Name | Parent Name |
Student Id | Student ID |
I have a registration form for the parents and was able to successfully register one parent and pull up/display the student name and attendance list for that specific student and parent. However, whenever I register a new parent and login to see the data of that parent and student, I am only able to change the parent name display, but the student name and the attendance details of the student remain the same student from the first registration. Below is the code:
//for parent name display
$q = "SELECT * FROM parent WHERE id = ".$_SESSION['id']."";
$r = $conn->query($q);
$num = $r->num_rows;
$rws = $r->fetch_assoc();
$full = $rws['pfname']." ".$rws['plname'];
Parent Name: <?php echo $full;?>
//for student name display
$qu = "SELECT student.* FROM student INNER JOIN parent ON (student.idno = parent.sidno) where parent.sidno = student.idno";
$r1 = $conn->query($qu);
$num = $r1->num_rows;
$rws1 = $r1->fetch_assoc();
$full1 = $rws1['sfname']." ".$rws1['slname'];
Student Name: <?php echo $full1;?>
//view by date (parent can select the date to view student attendance in a table)
if(isset($_POST['viewAttbydate'])){
$que = "SELECT student.* FROM student INNER JOIN parent ON (student.idno = parent.sidno) where parent.sidno = student.idno";
$r0 = $conn->query($que);
$num = $r0->num_rows;
$rws0 = $r0->fetch_assoc();
$admidno = $rws0['idno'];
If there's any way I am able to view the rest of the student data for the specific parent instead of seeing only the registered student connected to the first registered parent, that would be awesome!
if there's anymore data u need from me let me know, i appreciate any help i can get as i've been stuck with this. thank you!
I think the WHERE
clause in this SQL statement is wrong:
$que = "SELECT student.* FROM student INNER JOIN parent ON (student.idno = parent.sidno) where parent.sidno = student.idno";
I think you mean:
$que = "SELECT student.* FROM student INNER JOIN parent ON (student.idno = parent.sidno) WHERE parent.pid = ".$_SESSION['id'];
This will limit the query to just the students of the parent who is logged in.
You should also look into using parameterized queries to prevent SQL injection attacks.