Harvard Extension School, Fall 2018
CSCI E-12 Fundamentals of Web Site Development

## Turn this into HTML Output

    <?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());

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

Copyright © David Heitmeyer