Page 1 of 1

Passing a value from a dynamic select box

Posted: Mon Apr 03, 2006 11:24 am
by Addos
Hi I hope someone can help me out,

I have a field in my tbl_skuoptions and have called this 'embro' and in the table I have the following:

Option Name embro

6 inches 1
8 inches 1
10 inches 1
6 inches embroidery 2
8 inches embroidery 2
10 inches embroidery 2

When a selection above is made from my dynamic 'Select Box' I need to pass this ‘embro’ value i.e. 6 inches - embro value = 1 etc, to an 'if statement' on another page. What I'm stuck on is trying to work out how to get the value from the ‘select option’ code and how to query the database i.e. Select * from blah and blah Where blah etc. If anyone can help me out as I’m not experienced enough to follow all of this code as I’m trying to implement and tweak this to customise a page for myself.

I’m sure the bit of code I need to work on is the following (below) however the full page can be found here http://www.ahamay.com/helpp.php with this section highlighted and I appreciate it’s a large piece of code and that’s why I’m not posting it all here on the forum but I feel it might help my cause if it’s available in full should anyone wish to view it.


Thank you very much and I do appreciate any suggestions at all.

Code: Select all

if ($displayType == "Advanced"){
			$query_rsCWParentQuery = "SELECT S.SKU_ID, 
			O.option_ID, 
			O.option_Name, 
			O.option_Sort
			FROM tbl_skuoptions O
			INNER JOIN tbl_skuoption_rel SO
			ON O.option_ID = SO.optn_rel_Option_ID
			INNER JOIN tbl_skus S
			ON S.SKU_ID = SO.optn_rel_SKU_ID
			WHERE S.SKU_ShowWeb = 1
			AND S.SKU_ProductID = ". $productId;
			if($cartweaver->settings->allowBackOrders == 0) {
				$query_rsCWParentQuery .= " AND S.SKU_Stock <> 0 ";
			}
			$query_rsCWParentQuery .= " ORDER BY O.option_Sort";
			
			$rsCWParentQuery = $cartweaver->db->executeQuery($query_rsCWParentQuery);
			$rsCWParentQuery_recordCount = $cartweaver->db->recordCount;
			//$row_rsCWParentQuery = $cartweaver->db->db_fetch_assoc($rsCWParentQuery);
		 echo("<script language=\"JavaScript\" src=\"cw2/assets/scripts/dropdowns.js\"></script>
		  <script language=\"JavaScript\">
			var arrDynaList = new Array();
			var arrDL1 = new Array();\r\n");
			$currentRow = 0;
			$lastTFM_nest = "";
			$intFieldCounter=1;
			foreach ($rsCWAllOptions as $key => $row_rsCWAllOptions){
				$currentRow++;
				$tfm_nest = $row_rsCWAllOptions['optiontype_Name'];
				if ($lastTFM_nest != $tfm_nest) {
					$lastTFM_nest = $tfm_nest;
					echo("arrDL1[" . $intFieldCounter++ . "] = \"sel" . $currentRow . "\";\r\n");
					echo("arrDL1[" . $intFieldCounter++ . "] = \"addToCart\";\r\n");
				}//End of  Simulated Nested Repeat
			}

Posted: Mon Apr 03, 2006 11:46 am
by RobertGonzalez
Addos wrote:What I'm stuck on is trying to work out how to get the value from the ‘select option’ code and how to query the database i.e. Select * from blah and blah Where blah etc.
Your select options should each have a unique value assigned to them. Once the form is posted, each field in the form can be accessed by it's $_POST array var (ie, field name "joojoobee" will be accessed as $_POST['joojoobee']). Set the post var value equal to a var and, after validating the data, use the var in your SELECT query.

Code: Select all

<?php
$joojoobee = $_POST['joojoobee'];
// validate $joojoobee and then use it in the query
$sql = "SELECT * FROM mytable WHERE myfield = $joojoobee";
?>

Posted: Mon Apr 03, 2006 2:20 pm
by Addos
Thanks so much for taking the time to post a reply. I have run your suggestion and all it returns is the following:
Key Value
prodId = 46
result = 2
stockAlert =

I know I’m getting close but I still need to find the value of the ‘embro’ variable when I submit the form. This is where I’m stuck as I don’t seem to be able to find a way to add this to the code without getting a undefined variable message.

If you have any further ideas I’d be most grateful to hear them.
Thanks again
Brian

Posted: Mon Apr 03, 2006 3:20 pm
by RobertGonzalez
Is there a place on the net where we can see the html of the form you are trying to submit? Also, can you post a MySQL table dump of the tbl_skuoptions table?

If I am understanding this correctly, there is information in one table (tbl_skuoptions) that is populating a select box (list box). You want to capture the value of the selection option (list item) and reference that in your query on your result page. Am I correct in my understanding of your problem?

Posted: Mon Apr 03, 2006 4:55 pm
by Addos
“Is there a place on the net where we can see the html of the form you are trying to submit?” Sorry no I’m not live just yet.”

“Also, can you post a MySQL table dump of the tbl_skuoptions table?”
Sure here it is :-)

Code: Select all

CREATE TABLE `tbl_skuoptions` (
  `option_ID` int(11) NOT NULL auto_increment,
  `option_Type_ID` int(11) default NULL,
  `option_Name` varchar(50) default NULL,
  `option_Sort` int(11) default NULL,
  `option_Archive` tinyint(4) NOT NULL default '0',
  `embro` varchar(50) default NULL,
  PRIMARY KEY  (`option_ID`),
  KEY `option_ID` (`option_ID`),
  KEY `tbl_list_OptionTypestbl_SKUOptions` (`option_Type_ID`),
  KEY `tbl_list_OptionTypestbl_SKUOptions1` (`option_Type_ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=132 ;

-- 
-- Dumping data for table `tbl_skuoptions`
-- 

INSERT INTO `tbl_skuoptions` VALUES (1, 1, 'Very Small', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (2, 1, 'Small', 2, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (3, 1, 'Medium', 3, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (4, 1, 'Large', 4, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (5, 1, 'X-Large', 5, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (78, 15, 'Red', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (88, 18, 'Red', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (45, 7, 'Camo Grey', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (44, 7, 'Camo Blue', 2, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (43, 7, 'Camo Green', 3, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (42, 6, 'Royal Blue', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (41, 6, 'Baby Blue', 2, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (29, 4, '6 Inches (15cms)', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (30, 4, '8 Inches (20cms)', 2, 0, '2');
INSERT INTO `tbl_skuoptions` VALUES (31, 4, '10 Inches (25cms)', 3, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (32, 4, '12 Inches (30cms)', 4, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (33, 4, '14 Inches (36cms)', 5, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (34, 4, '16 Inches (41cms)', 6, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (35, 4, '18 Inches (46cms)', 7, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (36, 4, '20 Inches (51cms)', 8, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (37, 4, '22 Inches (56cms)', 9, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (38, 4, '24 Inches (61cms)', 10, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (39, 5, 'Black', 0, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (40, 5, 'Red', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (46, 8, 'Red', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (47, 8, 'Blue', 2, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (48, 8, 'Black', 3, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (49, 8, 'Camo Green', 4, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (50, 8, 'Camo Blue', 5, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (51, 8, 'Camo Grey', 6, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (52, 8, 'Red Quilted', 9, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (53, 8, 'Blue Quilted', 8, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (54, 8, 'Black Quilted', 7, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (55, 8, 'Camo Green Quilted', 12, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (56, 8, 'Camo Blue Quilted', 11, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (57, 8, 'Camo Grey Quilted', 10, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (58, 9, 'Red', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (59, 9, 'Black', 2, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (60, 9, 'Green', 3, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (61, 9, 'Pink', 4, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (62, 10, 'Pink', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (63, 10, 'Lilac', 2, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (64, 10, 'Black', 3, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (65, 11, 'Baby Blue', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (66, 11, 'Red', 2, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (67, 11, 'Hot Pink', 3, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (68, 12, 'Pink', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (69, 12, 'Blue', 2, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (70, 13, 'Blue', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (71, 13, 'Pink', 2, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (72, 13, 'Brown', 3, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (73, 13, 'Lilac', 4, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (74, 14, 'Red/Pink', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (75, 14, 'Pink/White', 2, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (76, 14, 'Blue/White', 3, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (77, 14, 'Black/White', 4, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (79, 15, 'Blue', 2, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (80, 15, 'Pink', 3, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (81, 15, 'Black', 4, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (82, 16, 'Pink', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (83, 16, 'Lilac', 2, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (84, 16, 'Lemon', 3, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (85, 17, 'Pink', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (86, 17, 'Lilac', 2, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (87, 17, 'Lemon', 3, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (89, 18, 'Black', 2, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (90, 18, 'Pink', 3, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (91, 18, 'Lilac', 4, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (92, 18, 'Lemon', 5, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (93, 18, 'Baby Blue', 6, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (94, 18, 'Cream', 7, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (95, 19, 'Red Thread', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (96, 19, 'Black Thread', 2, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (97, 19, 'Blue Thread', 3, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (98, 19, 'Pink Thread', 4, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (99, 19, 'Lilac Thread', 5, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (100, 19, 'Lemon Thread', 6, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (104, 4, '6 Inches (15cms) Embroidery', 11, 0, '2');
INSERT INTO `tbl_skuoptions` VALUES (105, 4, '8 Inches (20cms) Embroidery', 12, 0, '2');
INSERT INTO `tbl_skuoptions` VALUES (106, 4, '10 Inches (25cms) Embroidery', 13, 0, '2');
INSERT INTO `tbl_skuoptions` VALUES (107, 4, '12 Inches (30cms) Embroidery', 14, 0, '2');
INSERT INTO `tbl_skuoptions` VALUES (108, 4, '18 Inches (46cms) Embroidery', 16, 0, '2');
INSERT INTO `tbl_skuoptions` VALUES (109, 4, '16 Inches (41cms) Embroidery', 15, 0, '2');
INSERT INTO `tbl_skuoptions` VALUES (110, 4, '20 Inches (51cms) Embroidery', 17, 0, '2');
INSERT INTO `tbl_skuoptions` VALUES (111, 4, '22 Inches (56cms) Embroidery', 18, 0, '2');
INSERT INTO `tbl_skuoptions` VALUES (112, 21, 'Pink', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (113, 21, 'Red', 2, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (114, 21, 'Yellow', 3, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (115, 22, '6 Inches (15cms)', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (116, 22, '8 Inches (20cms)', 2, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (117, 22, '10 Inches (25cms)', 3, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (118, 22, '12 Inches (30cms)', 4, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (119, 22, '14 Inches (36cms)', 5, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (120, 22, '16 Inches (41cms)', 6, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (121, 22, '18 Inches (46cms)', 7, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (122, 22, '20 Inches (51cms)', 8, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (123, 22, '22 Inches (56cms)', 9, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (124, 22, '24 Inches (61cms)', 10, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (125, 23, 'Red', 1, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (126, 23, 'Black', 2, 0, '1');
INSERT INTO `tbl_skuoptions` VALUES (127, 23, 'Pink', 3, 0, NULL);
INSERT INTO `tbl_skuoptions` VALUES (128, 23, 'Lilac', 4, 0, NULL);
INSERT INTO `tbl_skuoptions` VALUES (129, 23, 'Lemon', 5, 0, NULL);
INSERT INTO `tbl_skuoptions` VALUES (130, 23, 'Baby Blue', 6, 0, NULL);
INSERT INTO `tbl_skuoptions` VALUES (131, 23, 'Cream', 7, 0, NULL);


“You want to capture the value of the selection option (list item) and reference that in your query on your result page. Am I correct in my understanding of your problem?”

Yes that’s basically it. I have one field called ‘embro’ and I’m running a small if statement on the Form so that if ‘embro’ = 2 then on submit I need a pop up window to appear as the from is processed and if on submit = 1 I want nothing to happen other than the form to submit. I have no problem in setting up the if statement on the form I just can’t seem to manage to find and pass the ‘embro’ value from the selection option (list item).

I think I need to query the database with something like if option_Type_ID = 4 and embro = 2 then let the pop up window appear but as I say I can’t seem to pass the values I need as embro keeps coming up undefined in anything I try.

Thank you again for your patience with me it is most appreciated.
b

Posted: Mon Apr 03, 2006 5:47 pm
by RobertGonzalez
How are you getting the value for 'embro' into your form's select field? It has to be there in order to pass, so that would be the first place I'd look. If 'embro' is in the form, then look at the form field name to see what $_POST var you need to check against to make sure the value is being sent. After that it is all details... setting the value for $_POST['embro'] to some var (like $embro) then doing your if's (if $embro == 1). But start with making sure that the embro field is getting into your form that is being posted.

Posted: Tue Apr 04, 2006 4:22 am
by Addos
Hi ya,
"How are you getting the value for 'embro' into your form's select field?"

To be honest this I think is most of my problem because I cannot seem to get this value into the form without all sorts of errors.

I have been playing around with the following at the top of the page but with little success:

Code: Select all

mysql_select_db($database_******, $*****
$query_GetEmbro = "SELECT * FROM tbl_skuoptions,tbl_products 
WHERE tbl_skuoptions.option_Type_ID = tbl_skuoptions.embro ";

$GetEmbro = mysql_query($query_GetEmbro, $snazzy) or die(mysql_error());
$row_GetEmbro = mysql_fetch_assoc($GetEmbro);
$totalRows_GetEmbro = mysql_num_rows($GetEmbro);
?>
<? if ($row_GetEmbro['option_Type_ID'] && $row_GetEmbro['embro'] == 4)
echo 'it works' ; ?>
Note I have changed the value in MySql database of embro to 4 from the dump in the previous post I gave.

If you have any other ideas I'd be a very happy person
thanks you very much for all your help so far.
Brian

Posted: Tue Apr 04, 2006 8:41 am
by RobertGonzalez
What do you mean when you say all sorts of errors? Basically what should happen is you should select the data frm the table with embro in it, then read the query result into an that, when it loops, echos out the values from the query into an HTML select field. Then, when the form is passed your vars are there for your use.

Please let us know what errors you are getting. This will be invavluable in finding out what is going on.