poppy Posted May 7, 2006 Share Posted May 7, 2006 I have a list/menu dropdown on my php page. It is dynamically populated from a mysql DB.I need to capture and store [b]seperately [/b] both the 'label' and the 'value' of the item chosen from the list so they can be used on a subsequent page - any ideas how this can best be done ?current code reads as followsname="dropdown"> <?phpdo { ?> <option value="<?php echo $row_rsswf['ItemValue']?>"><?php echo $row_rsswf['ItemName']?></option><?php} while ($row_rsswf = mysql_fetch_assoc($rsswf)); $rows = mysql_num_rows($rsswf); if($rows > 0) { mysql_data_seek($rsswf, 0); $row_rsswf = mysql_fetch_assoc($rsswf); }?></select>many thanksp Quote Link to comment https://forums.phpfreaks.com/topic/9251-capturing-output-from-dynamic-listmenu/ Share on other sites More sharing options...
AndyB Posted May 7, 2006 Share Posted May 7, 2006 When this form is submitted (and assuming the method is 'post'), the selected item will be found in the $_POST array as:[code]$picked = $_POST['dropdown']; // get SELECTed value[/code]Since that would only pass the value as your select options are presently written, you need to restructure your option value to include both the value and name of the selection. For example:[code] <option value="<?php echo $row_rsswf['ItemValue']. "|'. $row_rsswf['ItemName']?>"><?php echo $row_rsswf['ItemName']?></option>[/code]Then you can separate the two parts by 'exploding' the value of $picked into its components. That will make them available on the page to which the form is submitted. If you want them on other pages, storing them as session variables is probably simplest. Quote Link to comment https://forums.phpfreaks.com/topic/9251-capturing-output-from-dynamic-listmenu/#findComment-34089 Share on other sites More sharing options...
poppy Posted May 9, 2006 Author Share Posted May 9, 2006 cheers andyi have exploded the result as you suggest<?php$picked = $_POST['dropdown']; // get selected value and name from dropdownlist($optionvalue, $optionname) = explode("|", $picked); //assign values in the listed order?>it works - great !but, what i have subsequently realised though ( after many painful hours... ) is that what i need to do is to pass these two new values to another place within the code of the [b]same[/b]page, not the subsequent one as i had previously explained. that is to say that there is a php code block in the header of my page ( from an ecart template ) that needs to pick up these new values as column bindings [b]before[/b] moving to the subsequent ( cart ) page.this code block was working before by gathering [b]either [/b] the 'label name' or the 'value' from the 'dropdown' in the following way<rest of code block.....$Options = "".$_POST["dropdown"] .""; // column binding.....more code>and succesfully passing it on.now however if do this with one of the new values for starters<rest of code block.....$Options = "".$optionvalue.""; // column binding......more code>it passes nothing on !what stupid mistake am i making this time??p Quote Link to comment https://forums.phpfreaks.com/topic/9251-capturing-output-from-dynamic-listmenu/#findComment-34646 Share on other sites More sharing options...
poppy Posted May 31, 2006 Author Share Posted May 31, 2006 sorted it thanks for your helphad the explode in the wrong placelearning.p Quote Link to comment https://forums.phpfreaks.com/topic/9251-capturing-output-from-dynamic-listmenu/#findComment-40554 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.