<?php
include("connect.php");

$ISBN = $_GET["ISBN"];

$result = mysql_query("SELECT * FROM item WHERE ISBN = '$ISBN'");


$row = mysql_fetch_array($result);

echo "<div id='mainpage'>";
echo "<center>";
echo "<h3>Book Detail</h3>";
echo "</div>";

echo "<div id='bookmenu'>";
echo "<table border='0' cellspacing='2' cellpadding='1' bordercolor='black' width='80%'>";

	echo "<tr>";
	echo "<td colspan='3'></td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<th colspan='3' style='font-size:15pt'>".$row["itemName"]."</th>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td rowspan='6' weight='20%' align='center'>";
	echo "<img src='$row[itemImage]' height='200' weight='200' style='margin:10 10 10 10'>";
	echo "</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<th width='15%'>ISBN:</th>";
	echo "<td width='65%'>".$row["ISBN"]."</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<th>Author:</th>";
	echo "<td>".$row["itemAuthor"]."</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<th>Publisher:</th>";
	echo "<td>".$row["itemPublisher"]."</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<th>Issue Date:</th>";
	echo "<td>".$row["itemDate"]."</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<th>Category:</th>";
	echo "<td>".$row["itemCategory"]."</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td align='center'><br/>";
	echo "</td>";
	echo "<th>Price:</th>";
	echo "<td>RM";
	printf("%10.2f",$row["itemPrice"]);
	echo "</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td align='center'><br/>";
	echo "<th>Available:</th>";
	echo "<td>".$row["itemQuantity"]."</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td align='center'><br/>";
	echo "<th>Mininum Quantity:</th>";
	echo "<td>".$row["itemMin"]."</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td colspan='3'></td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<th colspan='3' style='font-size:15pt'><b>Summary:</b></th>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td colspan='3'>".$row["itemSummary"]."</td>";
	echo "</tr>";
echo "</table>";

echo "<table border='0' cellspacing='2' cellpadding='1' bordercolor='black' width='80%'>";

	echo "<tr>";
	echo "<th colspan='3' style='font-size:15pt'><b>Book Comment</b></th>";
	echo "</tr>";

	$result2 = mysql_query("SELECT * FROM bookmessage WHERE ISBN = '$ISBN'");
	
	$num_results2 = mysql_num_rows($result2);

if($num_results2>0){
for ($j=0; $j <$num_results2; $j++)
{
$row2 = mysql_fetch_array($result2);
echo "<tr>";
echo "<td width='10%'>".($j+1)."</td>";
echo "<td width='70%'>".$row2['comment']."<br/>";
echo "<font size='1'>Commented By ".$row2['memLname'].", ".$row2['time']."</font></td>";

echo "<form name='deletecomment' method='post' action='commentdelete.php'>";
echo "<td width='25%'><input type='hidden' name='memLname' value=".$row2['memLname']."><input type='hidden' name='ISBN' value=".$row2['ISBN']."><input type='submit' name='Delete' value='Delete'></td>";
echo "</form>";
echo "</tr>";
}
}else{
echo "<tr>";
echo "<td colspan='3'><center>Currently no comment here.</center></td>";
echo "</tr>";
}
	
echo "</table>";


echo "</div>";
echo "</center>";

$db = mysql_close();

?>