I'm trying to create a student class schedule system where students will be able to view the classes available and able to book themselves if they wish to take part.
I have created a main table called schedule along side 5 different tables for the classes.
Here is an image of the tables and what i'm trying to do.
https://i.stack.imgur.com/tysWG.jpg
On the main schedule planner, i want to only display the name of the class and ID's of students that have booked their attendance.
My question is, do i use a INSERT statement and retrieve data from the other tables or how can i achieve what i'm trying to do.
Here is what i've completed so far.
<?php
require_once 'login.php';
include ('header.html');
echo'<link rel="stylesheet" type="text/css" href="style.css">';
$dbserver = mysql_connect($dbhost, $dbuser, $dbpass);
if(!$dbserver)
{
die("MySQL connection failed: " . mysql_error());
}
$selection = mysql_select_db($dbname, $dbserver);
if(!$selection)
{
die("MySQL selection failed: " . mysql_error());
}
$query = "SELECT * FROM schedule
ORDER BY
CASE
WHEN ID = 'Monday' THEN 1
WHEN ID = 'Tuesday' THEN 2
WHEN ID = 'Wednesday' THEN 3
WHEN ID = 'Thursday' THEN 4
WHEN ID = 'Friday' THEN 5
END ASC";
//$query = "UPDATE schedule SET 9am='metaphysics3' WHERE id='monday'";
$result = mysql_query($query);
if(!$result)
{
die("MySQL query failed: " . mysql_error());
}
else{
print '<table>';
print "<tr>
<td><strong>May</stong></td>
<td><strong>9AM</stong></td>
<td><strong>10AM</stong></td>
<td><strong>11AM</stong></td>
<td><strong>12PM</stong></td>
<td><strong>13PM</stong></td>
<td><strong>14PM</stong></td>
<td><strong>15PM</stong></td>
<td><strong>16PM</stong></td>
</tr>";
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
print " <tr>
<td> {$row['ID']} </td>
<td> {$row['9AM']} </td>
<td> {$row['10AM']} </td>
<td> {$row['11AM']} </td>
<td> {$row['12PM']} </td>
<td> {$row['13PM']} </td>
<td> {$row['14PM']} </td>
<td> {$row['15PM']} </td>
<td> {$row['16PM']} </td>
</tr> ";
}
print '</table>';
}
mysql_close($dbserver);
?>