<html>
<head>
<title>Getting Books Information From DB</title>
</head>
<body>
<center><b>Books From My Book DB</b></center>
<center><i>(Query Executed: <?php echo(date("d M Y/D H:i:s a")) ?>)</i></center>
<br>
<table width="100%" border="1">
<tr>
	<th>Picture</th>
	<th>Book Name</th>
	<th>Author</th>
	<th>ISBN</th>
	<th>Price</th>
</tr>
<?
// This will read all the entries from the book database.
$host   = "localhost";
$dbName = "mmaaaco_ksecor";
$u = "mmaaaco_ksecor";
$p = "hamilton";

// Try to connect to the MYSQL server.
$conn = mysql_connect($host, $u, $p) 
        or 
        die ('I cannot connect to the database because: ' . mysql_error());

// Select the database that we will use.
mysql_select_db($dbName, $conn);

// Let's get info from the database.
//$query  = "SELECT * FROM $dbTable";
$query  = "SELECT * FROM book, author, book_author WHERE book.id = book_author.book_id AND author.id = book_author.author_id";

$result = mysql_query($query);

if ($result) {
   while ($row = mysql_fetch_assoc($result)) {
      $name  = $row['name'];
      $isbn  = $row['isbn'];
      $picId = $row['pictureId'];
      $price = $row['price'];
      $fName = $row['firstName'];
      $lName = $row['lastName'];	  
?>

<tr>
    <td><?php echo("<img src=\"$picId.jpg\">") ?></td>
    <td><?=$name?></td>
    <td><?php echo("$fName $lName")?></td>
    <td><?=$isbn?></td>	
    <td>$<?=$price?></td>
</tr>

<?php									
   }
}
else
   echo "Problem! Cannot get info from the database!";

mysql_close($conn); // Close the connection.
?>
</table>
<br>
<h5>
</h5>
</body>
</html>


