courses.php

<!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
  $mysqli = new mysqli('localhost','class','cscie12','coursecatalog');
  if ($mysqli->connect_errno) {
      echo "Failed to connect to mysql: ".$mysqli->connect_errno." ".$mysqli->connect_error;
  }
$dept_code = $_GET['department_code'];
$sqlescaped_dept_code = $mysqli->real_escape_string($dept_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 .= "'".$sqlescaped_dept_code."'";
$query .= ' order by course_group_long, num_int, num_char, title';

$result = $mysqli->query($query);

// Printing results in HTML
     echo "<table cellspacing='0' cellpadding='0'>\n";
$i = 0;
     while ($row = $result->fetch_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/>";
       echo "<span class='faculty'>$row[faculty_text]</span>";
       echo "<p class='description'>$row[description]</p></td>";
       echo "\t</tr>\n";
     }
echo "</table>\n";

// Free resultset
$result->free();
// Close connection
$mysqli->close();
?>

</body>
</html>