close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

product option problems

Thread began 3/31/2009 6:07 pm by stevesmith373400 | Last modified 4/02/2009 6:30 pm by Jason Byrnes | 3628 views | 16 replies |

stevesmith373400

product option problems

I am trying to put in product options. I have a table, "options" that lists all the options for every product. The options are identified by a group id # 1,2,3, etc. I am working on a category page and want the options to be shown here. Not every product on the page has options and there are different options for different products. When I do a recordset, "rsfoptions", it returns all of the options. When I look at the page in my browser every product has every option. I need help with the codinging . Ecart is not too user friendly on these things. I have pasted the recordset code below.

SELECT *
FROM options INNER JOIN items on items.optid=options.optgrpid
WHERE itemid=param

name=param
type=numeric
default value= 0
runtime value=$run_rsfrozen['itemid']

"itemid" is the pk column in the items (or product table). This table has a column identifing the option group id.

Any advice would be greatly appreciated.

Sign in to reply to this post

stevesmith373400

Are there any video tutorials available on this topic?

Sign in to reply to this post

Ray BorduinWebAssist

You can't refer to a recordset value directly as a parameter in DW recordsets.

One technique I have used is to add code above the recordset like:

<?php
$_GET['tempitemid'] = $run_rsfrozen['itemid'];
?>

Then set the parameter runtime value to: $_GET['tempitemid']

Sign in to reply to this post

stevesmith373400

I have seen this before but it doesn't seem to work for me. I believe my tables are not set up right. Could you suggest a sample table set up using multiple products with multiple options. Some products with no options, some products with unique options and some with shared options. Just names and columns would help. I know it is asking a lot. I have a good handle on relational databases but this has me boggled.

Sign in to reply to this post

Ray BorduinWebAssist

products table would have a productID autonumber and no reference to options as well as whatever other fields you want to track on a product by product basis.

optionsgroup table would have the option groupID autonumber and a groupName field, and that is it.

productoptions table would have the productOptionID autonumber, a productOptionGroupID (join to groupID) and optionProductID (join to products) and that is it.

options table would have an optionID autonumber and a optionGroupID (join to groupID) as well as any other information specific to this option.

This would give you complete flexability with regards to the database (and a relative nightmare when it comes to writing queries and a back end if you aren't experienced)

Sign in to reply to this post

stevesmith373400

Thanks. I will need to work through this. Let me ask you what may be a dumb question. I will have two recordsets per page. One that sorts the page to the right category and then one that will get the options. Even though I highlight the first recordset, I cannot determin in the code where one stops and the other begins in order to insert the get code you gave me.

Here is the code that highlights when either is selected. If you could indicate at what point I need to insert the " <?php
$_GET['tempitemid'] = $run_rsfrozen['itemid'];
?> " that would be great.

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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_aysconn, $aysconn);
$query_rsfrozen = "SELECT * FROM items WHERE itemcatid = '9'";
$rsfrozen = mysql_query($query_rsfrozen, $aysconn) or die(mysql_error());
$row_rsfrozen = mysql_fetch_assoc($rsfrozen);
$totalRows_rsfrozen = mysql_num_rows($rsfrozen);

$param_rsfoptions = "0";
if (isset($run_rsfrozen['itemid'])) {
$param_rsfoptions = (get_magic_quotes_gpc()) ? $run_rsfrozen['itemid'] : addslashes($run_rsfrozen['itemid']);
}
mysql_select_db($database_aysconn, $aysconn);
$query_rsfoptions = sprintf("SELECT * FROM options INNER JOIN items on items.optid=options.optgrpid WHERE items.itemid=%s", GetSQLValueString($param_rsfoptions, "int"));
$rsfoptions = mysql_query($query_rsfoptions, $aysconn) or die(mysql_error());
$row_rsfoptions = mysql_fetch_assoc($rsfoptions);
$totalRows_rsfoptions = mysql_num_rows($rsfoptions);
?>

Sign in to reply to this post

stevesmith373400

I have redone my tables and they match the ecommerce recipe example, which was not very clear or helpful, exactly. (By the way, in their example they use the run time value of $run_rsfrozen['itemid'].) I have tried your method. I put the $_GET['tempitemid'] in the runtime value. I then put the other php code in every possible place at the top of the page. It makes no difference. Every item still shows every possible option intstead of the options that are set for it. Here is the code. What do you think?

<?php
//WA eCart Include
require_once("WA_eCart/ayscart_PHP.php");
?><?php require_once('Connections/aysconn.php'); ?>
<?php
$ayscart->GetContent();
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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_aysconn, $aysconn);
$query_rsfrozen = "SELECT * FROM items WHERE itemcatid = '9'";
$rsfrozen = mysql_query($query_rsfrozen, $aysconn) or die(mysql_error());
$row_rsfrozen = mysql_fetch_assoc($rsfrozen);
$totalRows_rsfrozen = mysql_num_rows($rsfrozen);

$param_rsfoptions = "0";
if (isset($_GET['tempitemid'] )) {
$param_rsfoptions = (get_magic_quotes_gpc()) ? $_GET['tempitemid'] : addslashes($_GET['tempitemid'] );
}
mysql_select_db($database_aysconn, $aysconn);
$query_rsfoptions = sprintf("SELECT * FROM itemopt INNER JOIN options on options.itemoptid=itemopt.itemoption WHERE itemitemid=%s", GetSQLValueString($param_rsfoptions, "int"));
$rsfoptions = mysql_query($query_rsfoptions, $aysconn) or die(mysql_error());
$row_rsfoptions = mysql_fetch_assoc($rsfoptions);
$totalRows_rsfoptions = mysql_num_rows($rsfoptions);
?>
<?php
// WA eCart AddToCart
if (isset($_POST["ayscart_1_ATC"]) || isset($_POST["ayscart_1_ATC_x"])) {
$ATC_itemID = $_POST["ayscart_1_ID_Add"];
$ATC_AddIfIn = 0;
$ATC_RedirectAfter = "cart.php";
$ATC_RedirectIfIn = "";
if (isset($totalRows_rsfrozen) && $totalRows_rsfrozen > 0) {
$row_rsfrozen = WAEC_findRecordMySQL($rsfrozen, "itemid", $ATC_itemID);
if ($row_rsfrozen) {
$ATC_itemName = "".$row_rsfrozen['itemname'] ."";// column binding
$ATC_itemDescription = "".$row_rsfrozen['itemshortdesc'] ."";// column binding
$ATC_itemWeight = floatval("0");// column binding
$ATC_itemQuantity = "".$_POST["ayscart_1_Quantity_Add"] ."";// column binding
$ATC_itemPrice = floatval("".$row_rsfrozen['itemprice'] ."");// column binding
$ATC_itemOption = "".$_POST["ayscart_1_Option_Add"] ."";// column binding
mysql_data_seek($rsfrozen, 0);
$row_rsfrozen = mysql_fetch_assoc($rsfrozen);
}
}
$ATC_itemQuantity = floatval($ATC_itemQuantity);
if (is_numeric($ATC_itemQuantity) && $ATC_itemQuantity != 0) {
$ayscart->AddToCart($ATC_AddIfIn, $ATC_RedirectIfIn, $ATC_itemID, $ATC_itemName, $ATC_itemDescription, $ATC_itemWeight, $ATC_itemQuantity, $ATC_itemPrice, $ATC_itemOption);
if ($ATC_RedirectAfter != "" && $ayscart->redirStr == "") {
$ayscart->redirStr = $ATC_RedirectAfter;
}
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != "") {
$_SESSION['WAEC_ContinueRedirect'] = $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
}
else {
$_SESSION['WAEC_ContinueRedirect'] = $_SERVER['PHP_SELF'];
}
}
}
?>
<?php
// WA eCart Redirect
if ($ayscart->redirStr != "") {
header("Location: ".$ayscart->redirStr);
}
?>
<!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"><!-- InstanceBegin template="/Templates/cattemp.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Frozen Foods</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="cartcss/tempcss.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrapper">
<div id="header"><img src="Images/header.gif" /></div>
<div id="content">
<div id="CatSideBar"></div>
<div id="MBody"><!-- InstanceBeginEditable name="mbody" -->Please select your favorite frozen items to keep you cool during your stay.<p><table width="672" height="53" border="1">
<?php do { ?>
<tr>
<td width="205"><?php echo $row_rsfrozen['itemname']; ?></td>
<td width="100"><select name="ayscart_Option_list_<?php echo $ayscart->DisplayIndex; ?>" >
<?php
do {
?>
<option value="<?php echo $row_rsfoptions['optname']?>"><?php echo $row_rsfoptions['optname']?></option>
<?php
} while ($row_rsfoptions = mysql_fetch_assoc($rsfoptions));
$rows = mysql_num_rows($rsfoptions);
if($rows > 0) {
mysql_data_seek($rsfoptions, 0);
$row_rsfoptions = mysql_fetch_assoc($rsfoptions);
}
?>
</select></td>
<td width="150"><?php echo $row_rsfrozen['itemshortdesc']; ?></td>
<td width="189"><?php echo $row_rsfrozen['itemprice']; ?></td>
<td width="100"><form name="ayscart_1_ATC_<?php echo $row_rsfrozen["itemid"]; ?>" method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?><?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".$_SERVER["QUERY_STRING"]:""; ?>">
<p>
<input type="hidden" name="ayscart_1_ID_Add" value="<?php echo $row_rsfrozen["itemid"]; ?>" >
<input type="text" name="ayscart_1_Quantity_Add" value="1" size="4" >
<select name="ayscart_1_Option_Add">
<?php
do {
?>
<option value="<?php echo $row_rsfoptions['optname']?>"><?php echo $row_rsfoptions['optname']?></option>
<?php
} while ($row_rsfoptions = mysql_fetch_assoc($rsfoptions));
$rows = mysql_num_rows($rsfoptions);
if($rows > 0) {
mysql_data_seek($rsfoptions, 0);
$row_rsfoptions = mysql_fetch_assoc($rsfoptions);
}
?>
</select>
<input type="image" src="WA_eCart/Images/Pacifica/Btn5_EN_addtocart.gif" border="0" value="Add to Cart" name="ayscart_1_ATC">
</p>
</form>
</td>
</tr>
<?php } while ($row_rsfrozen = mysql_fetch_assoc($rsfrozen)); ?>
</table>
</p><!-- InstanceEndEditable --></div>
</div>
<div id="footer"><img src="Images/footer-1.gif" /></div>
</div>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($rsfrozen);

mysql_free_result($rsfoptions);
?>

Sign in to reply to this post

Ray BorduinWebAssist

If that returns all results, then the query:

SELECT * FROM itemopt INNER JOIN options on options.itemoptid=itemopt.itemoption WHERE itemitemid = param

must return all results. Have you tested it in your mysql admin to see if your data is entered correctly. There doesn't appear to be a problem with this page.

You could add:

<?php echo($query_rsfoptions); ?>

This will tell you the exact query it is using. Why it returns so many results I guess could be a data integrity issue in the database.

Sign in to reply to this post

stevesmith373400

I spoke to the tech guys and basically they told me that you can't show options on a catalog page with out serious hand coding. So I am trying another tactic. I want to insert a text field in the add to cart button form that the customer can type in the desired option. I can insert the field but I can't seem to get the typed in result to show in the cart display page. Do you have any thoughts. I made sure the field was included in the ATC button form. I believe I bound it to the option column but it still does not produce the results. Any thoughts?

Sign in to reply to this post

Ray BorduinWebAssist

A few possible problems:

1) You didn't upload your cart with the new column
2) You didn't update your add to cart server behavior
3) You didn't drag/drop the column onto the display page to be displayed

It is probably one of those.

A correction is that you really don't need hand coding to get options working. You need to use native DW functionality and hand written SQL to access your options from your database. No physical writing of php should be necessary, but that doesn't mean it isn't complex.

Sign in to reply to this post
loading

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...