"); exit(); } } getDatabaseLink($link); beginRO($link); function viewitem($link, $itemId) { $row = getAnyItem($link, $itemId); if (!$row) { die("

ERROR: Sorry, but this item does not exist.


\n"); } $maxBid = $row["max_bid"]; if ($maxBid == 0) { $maxBid = $row["initial_price"]; $buyNow = $row["buy_now"]; $firstBid = "none"; } else { if ($row["quantity"] > 1) { $xRes = sql_query("SELECT bid,qty FROM bids WHERE item_id=".$row["id"]." ORDER BY bid DESC LIMIT ".$row["quantity"], $link) or die("ERROR: Quantity query failed"); $nb = 0; while ($xRow = sql_fetch_array($xRes)) { $nb = $nb + $xRow["qty"]; if ($nb > $row["quantity"]) { $maxBid = $row["bid"]; break; } } } $firstBid = $maxBid; $nbOfBidsResult = sql_query("SELECT COUNT(*) AS bid FROM bids WHERE item_id=".$row["id"], $link) or die("ERROR: Nb of bids query failed"); $nbOfBidsRow = sql_fetch_array($nbOfBidsResult); $nbOfBids = $nbOfBidsRow["bid"]; sql_free_result($nbOfBidsResult); } printHTMLheader("RUBiS: Viewing ".$row["name"]); printHTMLHighlighted($row["name"]); print("\n". "
Currently$maxBid\n"); // Check if the reservePrice has been met (if any) $reservePrice = $row["reserve_price"]; if ($reservePrice > 0) { if ($maxBid >= $reservePrice) { print("(The reserve price has been met)\n"); } else { print("(The reserve price has NOT been met)\n"); } } $sellerNameRow = getUser($link, $row["seller"]); $sellerName = $sellerNameRow["nickname"]; print("
Quantity".$row["quantity"]."\n"); print("
First bid$firstBid\n"); print("
# of bids$nbOfBids (bid history)\n"); print("
Seller$sellerName (Leave a comment on this user)\n"); print("
Started".$row["start_date"]."\n"); print("
Ends".$row["end_date"]."\n"); print("
\n"); // Can the user by this item now ? if ($buyNow > 0) print("

". "". " You can buy this item right now for only \$$buyNow

\n"); print(" on this item\n"); printHTMLHighlighted("Item description"); print($row["description"]); print("

\n"); } wrap(true, 'viewitem', $link, $itemId); commit($link); sql_close($link); printHTMLfooter($scriptName, $startTime); ?>