Create another PHP file that displays course information based upon a department_code parameter.
courses.php
- take a "department_code" parameter and produce alist of courses for that department.Need to link to to courses.php:
Modify the department listing to include the hyperlink:
<!DOCTYPE html>
<html>
<head>
<title>Departments</title>
<link rel="stylesheet" href="site.css" type="text/css"/>
</head>
<body>
<h1>Faculty of Arts & 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());
// Printing results in HTML
echo "<ul>\n";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<li>";
echo "<a href=\"courses.php?department_code=$row[department_code]\">$row[department_short]</a>";
echo "</li>\n";
}
echo "</ul>\n";
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);
?>
</body>
</html>
Copyright © David Heitmeyer