Query Results
    
    
        setAttribute(PDO::ATTR_ERRMODE,
                                   PDO::ERRMODE_EXCEPTION);
                
                // Constrain the query if we got first and last names.
                if ((strlen($first) > 0) && (strlen($last) > 0)) {
                    $query = "SELECT * FROM people ".
                             "WHERE first = '$first' ".
                             "AND   last  = '$last'";
                }
                else {
                    $query = "SELECT * FROM people";  
                }
                // We're going to construct an HTML table.
                print "
\n";
                
                // Query the database.
                $data = $con->query($query);
                $data->setFetchMode(PDO::FETCH_ASSOC);
                
                // Construct the HTML table row by row.
                // Start with a header 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";
            }
            catch(PDOException $ex) {
                echo 'ERROR: '.$ex->getMessage();
            }        
        ?>