<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
  <title>Book Report</title>
  <link rel="stylesheet" type="text/css" href="../style.css" />
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head> 

<body>

<?php

// function definitions first
function doGetAll() {
    
$sortby $_GET['sortby'];

    if (
$sortby == "") {$sortby "lastname";}

    
$sql "select time, lastname, firstname, title, year, location, quotes from bookstuff.entries order by $sortby;";

    print 
"query is: $sql";

    
$result mysql_query($sql) or die("Mysql query failed");

    echo <<<END

     <p>Here are all the books sorted by 
$sortby:</p>

    <table border=\"1\">
    <tr><th><a href="bookreportpub.php?sortby=time">Date</a></th>
    <th><a href="bookreportpub.php?sortby=lastname">Last Name</a></th>
    <th><a href="bookreportpub.php?sortby=firstname">First Name</a></th>
    <th><a href="bookreportpub.php?sortby=title">Title</a></th>
    <th><a href="bookreportpub.php?sortby=year">Year</a></th>
    <th><a href="bookreportpub.php?sortby=location">Location</a></th>
    <th>Quotes</th></tr>
END;

    while (
$r mysql_fetch_array($result)) {
      
// This magically sets $xyz to the value of the column named
          // xyz in the current query.
      
extract($r);
          
// If extract is not used, achieve the same effect by doing
          //  $r["xyz"]
          // Also, mysql_fetch_row returns a regular positional array
          // instead of an associative array.

//    $time = date("D M j G:i:s T Y",$time); 
    
$time date("n/j/Y",$time);

    print 
"<tr><td>$time</td><td>$lastname</td><td>$firstname</td><td>$title</td><td>$year</td><td>$location</td><td>$quotes</td></tr>";
      }
    print 
"</table>";
}


    
$db mysql_connect("vh216602.truman.edu""bookuserSel""AbQm");
if (!
$db) {
    print 
"Error - Could not connect to mysql";
    exit;
}

 
$er mysql_select_db("bookstuff");
 if (!
$er) {
     print 
"Error - Could not select bookstuff database";
    exit;
 }

doGetAll();