kelsofield Posted November 23, 2009 Share Posted November 23, 2009 I am trying to get the values posted from a form select. The select name is dynamic, meaning that the name value is defined by a database record. In the form processing script, I want to call back that value via a $_REQUEST. I cannot know in advance what the value of the $_request will be (eg, $var=$_REQUEST['foo']; ) but I do know that the value is one originitating from a database table. Knowing this I create a database call, then use a foreach to loop through the possible values. I want to create a $_request for each pass. eg.. $prod_prop_name=mysql_query("SELECT * FROM `dshop_options_name`"); $prod_prop_name_array= array(); while($data9=mysql_fetch_array($prod_prop_name)) {$prod_prop_name_array[]=$data9;} foreach($prod_prop_name_array as $rowNum => $data9){ $option_id=$data9[0]; $option_name=$data9[1]; if($option_name==""){} else{$varnval=$_REQUEST[$option_name]; // this is my try at getting the var value echo "$varnval"; // this is the output test } } Problem I am having is that on the local server, I get a value, but on the webserver I get none. You can see I am using an echo to see what happens. $varnval Can anyone suggest a workaround for this issue? Many Thanks KF Quote Link to comment https://forums.phpfreaks.com/topic/182570-populate-a-_request-variable-value-from-database-record-how/ Share on other sites More sharing options...
premiso Posted November 23, 2009 Share Posted November 23, 2009 Well how about this, do you create the select dropdown menu or do you have access to that code? If you do, why not add a dbs_ before the name of the select, then you can easily access it using a foreach loop: <?php foreach ($_REQUEST as $key => $val) { if (strstr($key, "dbs_")) { $value = $val; break; } } echo "The key used was $key which contained $value for a value."; ?> If you can do it that way, much easier and way more efficient Quote Link to comment https://forums.phpfreaks.com/topic/182570-populate-a-_request-variable-value-from-database-record-how/#findComment-963616 Share on other sites More sharing options...
kelsofield Posted November 23, 2009 Author Share Posted November 23, 2009 thanks for the reply.. this is my complete select build.. $prod_prop_name=mysql_query("SELECT * FROM `dshop_options_name`"); $prod_prop_name_array= array(); while($data9=mysql_fetch_array($prod_prop_name)) {$prod_prop_name_array[]=$data9;} foreach($prod_prop_name_array as $rowNum => $data9) { $prod_prop_id=$data9[0]; $prod_prop_title=$data9[1]; //////////////////////////////////////////////////////////////////// $prod_prop_attri=mysql_query("SELECT * FROM `dshop_options_values` WHERE `prod_id`='".$selected_product."' AND `attri_name`='".$prod_prop_title."' ORDER BY `attri_value` ASC "); $prod_prop_attri_array= array(); while($data10=mysql_fetch_array($prod_prop_attri)) {$prod_prop_attri_array[]=$data10;} if(!$prod_prop_attri_array){} else{ ?> <div class='left'><?php echo $prod_prop_title?> <select name='<? echo $prod_prop_title?>'> <option value="select">Select</option> <?php foreach($prod_prop_attri_array as $rowNum => $data10){ $itemname=$data10[2]; $itemvalue=$data10[3]; $itemprice=$data10[4]; if($itemprice<="0"){ ?> <option value='<?php echo $itemvalue?>'><?php echo $itemvalue?></option> </select> <?php } else{ ?> <option value='<?php echo $itemvalue?>'><?php echo $itemvalue." - ".$currency_type.$itemprice?></option> <?php } } ?> </select></br></br></div> <?php } } Any help appreciated, i have to produce a viable working demo for the client in the morning, and already 01:44GMT here. Although i am tackling a very complex system (in total), by experience of array use is still building. KF Quote Link to comment https://forums.phpfreaks.com/topic/182570-populate-a-_request-variable-value-from-database-record-how/#findComment-963618 Share on other sites More sharing options...
premiso Posted November 23, 2009 Share Posted November 23, 2009 Was my instructions/logic not clear? <select name='dbs_<? echo $prod_prop_title?>'>[code] Is the only change you would need to do, adding that prefix will allow you to know which item in the request array you want to access on the next page. Then you would use the code I posted above to pull it out on the next page. Quote Link to comment https://forums.phpfreaks.com/topic/182570-populate-a-_request-variable-value-from-database-record-how/#findComment-963626 Share on other sites More sharing options...
kelsofield Posted November 23, 2009 Author Share Posted November 23, 2009 no, thanks.. iv been working on it, logic sound, almost done.. ty for your suggestion.. Quote Link to comment https://forums.phpfreaks.com/topic/182570-populate-a-_request-variable-value-from-database-record-how/#findComment-963633 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.