|
CS479/579 - Web Programming II
| Displaying exercises/e9/solution/item.php
<?php
$myconn = new mysqli("localhost", "sbaker", "sbaker", "sbaker");
$iid = isset($_GET['iid'])? (int)$_GET['iid'] : null;
if ($iid == null) header("location: store.php");
function getvendor($vid) {
global $myconn;
$st = $myconn->prepare("SELECT name FROM vendor WHERE vid=?");
$st->bind_param("i", $vid); $st->bind_result($name);
$st->execute(); $st->fetch(); $st->close();
return $name;
}
function getcomponentname($cid) {
global $myconn;
$st = $myconn->prepare("SELECT name FROM component WHERE cid=?");
$st->bind_param("i", $cid); $st->bind_result($name);
$st->execute(); $st->fetch(); $st->close();
return $name;
}
$st = $myconn->prepare("SELECT cid,vid,model,description,price,amount
FROM inventory WHERE iid = ?");
$st->bind_param("i", $iid);
$st->bind_result($cid, $vid, $model, $description, $price, $amount);
$st->execute();
$st->fetch();
$st->close();
$vendor = getvendor($vid);
$component = getcomponentname($cid);
?>
<!DOCTYPE html>
<html>
<head>
<title> Item </title>
<meta charset='utf-8'>
<link rel=stylesheet type='text/css' href='style.css'>
</head>
<body>
<table id='ctbl'>
<tr>
<td colspan=3 id='top'><a href='store.php'>Very Generic Super Computer Store</a><br>
<tr>
<td colspan=3>
<a href='store.php'> Home </a> >
<a href='component.php?cid=<?php echo "$cid";?>'><?php echo "$component";?></a> >
Item #<?php echo "$iid";?>
<tr>
<td class='bigpic'><?php echo "{$model[0]}"; ?>
<td valign=top align=center>
<div class='vendor'><?php echo "$vendor";?></div>
<div class='model'><?php echo "$model";?></div>
<div class='component'><?php echo "$component";?></div>
<td valign=top><div class='price'>$<?php echo "$price";?></div>
<?php
if ($amount > 0) echo "In stock!";
else echo "Out of stock";
?>
</table>
</body>
</html>
|