I am studying PHP and we have a project that we got yesterday. I need to build a system that manages a school. I need to create courses and students and I need to be able to assign a student to more than one course. I need to be able to show the list of students for each course and if I choose a student, I need to show all the courses he is listed to. My question is how to plan the DB correctly in order to be able to show all this data. I think I need to use an array of student ID's in each course but I have no idea where and how to start (We did not learn it... like many other things....).
Help will be appreciated.
New content:
I have created 3 tables. 1. students 2. courses 3. coursestudent (Which has: - id - studentid - courseid )
I need help writing a query that will count how many are listed to each course.
This is my code:
<table id="courses" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th class="text-center">#</th>
<th class="text-center">שם הקורס</th>
<th class="text-center">כמות סטודנטים בקורס</th>
</tr>
</thead>
<tbody>
<?php
$counter=1;
$sql = "SELECT * FROM courses";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($result)){
echo '
<tr class="text-center">
<td>'. $counter .'</td>
<td>'. $row['coursename'] .'</td>
<td>';
$sqlstudents = "SELECT * FROM coursestudent INNER JOIN students ON coursestudent.studentid=students.studentid WHERE courseid='$counter'";
$resultstudents = mysqli_query($conn, $sqlstudents);
$rowcount=mysqli_num_rows($resultstudents);
echo $rowcount.'</td><tr>';
$counter++;
}
?>
</tbody>
</table>
It returns 0 for each course.