1

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); 
?>
  • 2
    not even sure where to begin (depricated) look up joins that may be what are looking for – happymacarts Nov 22 '16 at 20:45
  • 1
    ***Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).*** [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Nov 22 '16 at 20:47

0 Answers0