<?php
include("connect.php");
$result = mysql_query("SELECT * FROM item ORDER BY itemDate DESC");   
echo "<tr>";
for($i=0; $i<1; $i++)
{
$row = mysql_fetch_array($result);
echo "<td width='20%'>";
echo "<table width='100%'>";
echo "<form name='qform' method='GET' action='indexaddcart.php'>";
echo "<tr>";
echo "<td align='center' height='100pt'>";
echo "<a href='bookviewpage.php?ISBN=".$row["ISBN"]."'><center><img src=/bookstore/bookstaff/".$row["itemImage"]." border='0' width='80' height='120'></center></a>";echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td height='40pt' valign='top' align='center'>";
echo "<input type='hidden' name='itemName' value='".$row["itemName"]."'><a href='bookviewpage.php?ISBN=".$row["ISBN"]."'><center>".$row["itemName"]."</center></a><br/>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td height='40pt' valign='top' align='center'>";
echo "<div id='length'>";
echo "<font maxlength='300pt'>$row[itemSummary]</font>";
echo "</div>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td align='center'><b>Price: RM ";
printf("%10.2f",$row["itemPrice"]);
echo "</b></td>";
echo "</tr>";

echo "<tr>";
echo "<td><br/></td>";
echo "</tr>";

echo "<tr>";
echo "<td align='center'>";
echo "<a href='bookviewpage.php?ISBN=".$row["ISBN"]."'><font size='3pt' color='red'><center>View Details</center></font></a>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td align='center'><br/>";
	if($row[itemQuantity]>0){
	$tem = $row[itemQuantity];
	echo "<name='temQuantity'>";
	echo "<select name='temQuantity'>";
	for($j=1; $j<=$tem; $j++)
	{
	echo "<option value='$j'>".$j;
	echo "</option>";
	}
	echo "</select>";
	echo "<input type='hidden' name='ISBN' value='$row[ISBN]'>";
	echo "<input type='hidden' name='itemPrice' value='$row[itemPrice]'>";
	echo "<input type='submit' name='add' value='Add Cart'>";
}else{
	echo "<name='temQuantity' value='".$row["temQuantity"]."'>";
	echo "<select name='temQuantity' onchange='this.form.submit()' value='Save' name='Save''>";
	$temQuantityArray = array("1", "2", "3", "4", "5", "6", "7", "8", "9");
	for($m = 0; $m < 9 ; $m++)
	{if($row["temQuantity"] == $temQuantityArray[$m])
	{echo "<option selected>".$temQuantityArray[$m];
	}else{
	echo "<option>".$temQuantityArray[$m];
	}
	}
	echo "</select>";
	echo "<input type='hidden' name='ISBN' value='$row[ISBN]'>";
	echo "<input type='hidden' name='itemPrice' value='$row[itemPrice]'>";
	echo "<input type='submit' name='add' value='Add Cart'>";
	}
echo "</td>";
echo "</tr>";
echo "</form>";
echo "</table>";	
echo "</td>";
}
echo "</tr>";

echo "</table>";
?>