Dynamic Form Menu
Hi Jason,
This is a bare-bones page to test the code on before I add a cart to my product pages.
I'm also trying to figure out how to add the individual sizes and prices into the repeating section underneath the item description, but it won't allow "nesting".
<?php require_once('Connections/connSpectrum.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_connSpectrum, $connSpectrum);
$query_rsItems = "SELECT ItemID, ItemCatID, ItemName, ItemDesc, ItemSKU, ItemImage, FROM items ORDER BY ItemID ASC";
$rsItems = mysql_query($query_rsItems, $connSpectrum) or die(mysql_error());
$row_rsItems = mysql_fetch_assoc($rsItems);
$totalRows_rsItems = mysql_num_rows($rsItems);
$varItem_rsSizes = "1";
if (isset($row_rsItems['ItemID'])) {
$varItem_rsSizes = $row_rsItems['ItemID'];
}
mysql_select_db($database_connSpectrum, $connSpectrum);
$query_rsSizes = sprintf("SELECT items.ItemID, options.OptionID, options.Option, options.OptionPrice, options.OptionWeight FROM items LEFT OUTER JOIN itemoptions ON items.ItemID = itemoptions.ItemID INNER JOIN options ON itemoptions.OptionID = options.OptionID WHERE items.ItemID = %s", GetSQLValueString($varItem_rsSizes, "int"));
$rsSizes = mysql_query($query_rsSizes, $connSpectrum) or die(mysql_error());
$row_rsSizes = mysql_fetch_assoc($rsSizes);
$totalRows_rsSizes = mysql_num_rows($rsSizes);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Product Page</title>
<link href="css/global.css" rel="stylesheet" type="text/css" />
</head>
<body background="img/metgrad.jpg">
<div id="container">
<div id="banner">
<p><img src="img/header2.gif" alt="" width="950" height="141" longdesc="http://www.fww.com/" /></p>
</div>
<?php do { ?>
<div class="ul">
<p><?php echo $row_rsItems['ItemName']; ?></p>
<p><?php echo $row_rsItems['ItemDesc']; ?></p>
<p><?php echo $row_rsItems['ItemSKU']; ?></p>
<p><img src="img/small/<?php echo $row_rsItems['ItemImage']; ?>" alt="image" /></p>
<p><?php echo $row_rsSizes['Option']; ?></p>
<form id="form1" name="form1" method="post" action="">
<label for="sizes"></label>
<select name="sizes" id="sizes">
<option value="null">--Please select a size--</option>
<?php
do {
?>
<option value="<?php echo $row_rsSizes['OptionID']?>"><?php echo $row_rsSizes['Option']?></option>
<?php
} while ($row_rsSizes = mysql_fetch_assoc($rsSizes));
$rows = mysql_num_rows($rsSizes);
if($rows > 0) {
mysql_data_seek($rsSizes, 0);
$row_rsSizes = mysql_fetch_assoc($rsSizes);
}
?>
</select>
</form>
<p> </p>
</div>
<?php } while ($row_rsItems = mysql_fetch_assoc($rsItems)); ?>
</div>
</body>
</html>
<?php
mysql_free_result($rsItems);
mysql_free_result($rsSizes);
?>
Thanks so much!