Jump to content

Recommended Posts

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 follows

name="dropdown">
<?php
do {
?>
<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 thanks

p
Link to comment
https://forums.phpfreaks.com/topic/9251-capturing-output-from-dynamic-listmenu/
Share on other sites

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

i have exploded the result as you suggest

<?php
$picked = $_POST['dropdown']; // get selected value and name from dropdown
list($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
  • 3 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.