\n";
                
            // Construct the HTML table row by row.
            $doHeader = true;
            foreach ($data as $row) {
                    
                // The header row before the first data row.
                if ($doHeader) {
                    print "        \n";
                    foreach ($row as $name => $value) {
                        print "            | $name\n";
                    }
                    print " | 
\n";
                    $doHeader = false;
                }
                    
                // Data row.
                print "        \n";
                foreach ($row as $name => $value) {
                    print "            | $value\n";
                }
                print " | 
\n";
            }
            
            print "    \n";
        }
        
        $first = filter_input(INPUT_GET, "firstName");
        $last  = filter_input(INPUT_GET, "lastName");
        
        try {
            if (empty($first) || empty($last)) {
                throw new Exception("Missing first or last name.");
            }
                
            print "Students of $first $last
\n";
        
            // Connect to the database.
            $con = new PDO("mysql:host=localhost;dbname=school",
                           "root", "sesame");
            $con->setAttribute(PDO::ATTR_ERRMODE,
                               PDO::ERRMODE_EXCEPTION);
            
            $query = "SELECT student.first, student.last, subject ".
                     "FROM student, teacher, class, student_class ".
                     "WHERE teacher.last = '$last' ". 
                     "AND teacher.first = '$first' ".
                     "AND teacher_id = teacher.id ".
                     "AND code = class_code ".
                     "AND student.id = student_id ".
                     "ORDER BY subject, student.last";
            // Fetch the matching rows.
            $data = $con->query($query);
            $data->setFetchMode(PDO::FETCH_ASSOC);
            
            // $data is a result set.
            if ($data->rowCount() > 0) {
                constructTable($data);
            }
            else {
                print "(No students.)
\n";
            }
        }
        catch(PDOException $ex) {
            echo 'ERROR: '.$ex->getMessage();
        }    
        catch(Exception $ex) {
            echo 'ERROR: '.$ex->getMessage();
        }
    ?>