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

## The entire "departments-simple.php"

- http://cscie12.dce.harvard.edu/cgi/courses/departments-simple.php

    <!DOCTYPE html>
    <html>
     <head>
      <title>Departments</title>
      <link rel="stylesheet" href="site.css" type="text/css"/>
     </head>
     <body>
    <h1>Faculty of Arts &amp; Sciences</h1>
    <h2>Departments</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');

    // Performing SQL query
    $query = 'SELECT distinct department_short, department_code FROM courses order by department_short';
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());

    // iterating through results
    echo "<ul>\n";
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        echo "<li>";
        echo $row['department_short'];
        echo "</li>\n";
     }
    echo "</ul>\n";

    // Free resultset
    mysql_free_result($result);

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

     </body>
    </html>

Copyright © David Heitmeyer