Harvard Extension School
CSCI E-12 Fundamentals of Web Site Development | Fall 2019

## courses.php

- courses.php?department_code=CHEM
- courses.php?department_code=MCB

    <!DOCTYPE html>
    <html>
     <head>
      <title>FAS Courses</title>
      <link rel="stylesheet" href="site.css" type="text/css"/>
     </head>
     <body>
    <h1>Faculty of Arts &amp; Sciences</h1>
    <p><a href="departments.php">Return to Department List</a></p>
    <h2>Department <?php echo $_GET[department_code] ?></h2>
    <?php
    // Connecting, selecting database
    $link = mysql_connect('localhost', 'class', 'dbpasswd')
         or die('Could not connect: ' . mysql_error());
         mysql_select_db('coursecatalog') or die('Could not select database');

    $dept_code = $_GET['department_code'];

    // Performing SQL query
    $query = 'SELECT course_group_long, num_int, num_char, term, title, description, faculty_text';
    $query .= ' from courses where department_code = ';
    $query .= "'".mysql_escape_string($dept_code)."'";
    $query .= ' order by course_group_long, num_int, num_char, title';

    $result = mysql_query($query) or die('Query failed: ' . mysql_error());
    // Printing results in HTML
         echo "<table cellspacing='0' cellpadding='0'>\n";
    $i = 0;
         while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
           $class = $i++ % 2 ? 'evenrow' : 'oddrow' ;
           echo "\t<tr class='$class'>\n";
           echo "<td class='abbrev'>$row[course_group_long] $row[num_int] $row[num_char]</td>";
           echo "<td class='long'><strong>$row[title]</strong><br/>$row[faculty_text]";
           echo "<p class='description'>$row[description]</p></td>";
           echo "\t</tr>\n";
         }
    echo "</table>\n";

    // Free resultset
    mysql_free_result($result);

    // Closing connection
    mysql_close($link);
    ?>

    </body>
    </html>

Copyright © David Heitmeyer