close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Dynamic Form Menu

Thread began 8/18/2012 3:55 pm by Loretta439108 | Last modified 8/22/2012 1:39 pm by Loretta439108 | 1401 views | 6 replies |

Loretta439108

Dynamic Form Menu

Hello,

I'm trying to put a dynamic form menu within a repeating section, in order to give the option to choose sizes. The sizes vary for each individual item (they change from item to item) and I'm having trouble setting up my recordset and menu to show the appropriate choices. I have 3 tables - an item table, an option table with the sizes, and an intermediate itemoption table linking the two tables. I want this information to be passed to ecart.

This is how I set up the recordset (which I suspect is wrong):

$varItem_rsSizes = "1";
if (isset($_GET['ItemID'])) {
$varItem_rsSizes = $_GET['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);
?>

And this is the form:

<form id="form1" name="form1" method="post" action="">
<label for="sizes">Sizes & Prices:</label>
<select name="sizes" id="sizes">
<option value="null" <?php if (!(strcmp("null", $row_rsItems['ItemID']))) {echo "selected=\"selected\"";} ?>>--Please select a size--</option>
<?php
do {
?>
<option value="<?php echo $row_rsSizes['OptionID']?>"<?php if (!(strcmp($row_rsSizes['OptionID'], $row_rsItems['ItemID']))) {echo "selected=\"selected\"";} ?>><?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>

Can anyone tell me how to fix this from within Dreamweaver's interface?

Thanks!

Sign in to reply to this post

Jason ByrnesWebAssist

this will require some rearranging of the code.

first, instead of using the $_GET['ItemID'] as the run time value for the varItem parameter, you need to use the ItemID from the main recordset $row_rsItems['ItemID']


Second, the code for the rsSizes recordset needs to be moved so that it is inside the repeat region.

Sign in to reply to this post

Loretta439108

Hi Jason,

Thanks so much for the help!

I changed the run time value for the varItem parameter as follows:

$varItem_rsSizes = "1";
if (isset($row_rsItems['ItemID'])) {
$varItem_rsSizes = $row_rsItems['ItemID'];

I'm not quite sure what you mean by moving the rsSizes recordset code inside the repeat region. Could you explain what you mean? Dreamweaver inserted it for me.

Sign in to reply to this post

Jason ByrnesWebAssist

The recordset code will be created in the head of the page before the doc type tag.

Since you want to create a unique record set for each product that is being displayed, the recordset code will need to be moved so that it is inside the repeat region.

if you need more specifics than that, please send a copy of your page.

Sign in to reply to this post

Loretta439108

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>&nbsp;</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!

Sign in to reply to this post

Jason ByrnesWebAssist

so, this line begins the repeat region:
<?php do { ?>

the recordset needs to be after that line:

<?php do { ?>
<?php
$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);
?>

Sign in to reply to this post

Loretta439108

Dynamic Form Menu

Hi Jason,

Thanks so much, it works perfectly!

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...