Jump to content

[SOLVED] Multiple


unidox

Recommended Posts

suppose you have these options in select

male and female

than you can use as mentioned below:

 

<?php
$a = array('male'=>'Male', 'female'=>'Female');
?>
<select name="abc">
<?php
foreach($a AS $key=>$value){
echo "<option value=\"".$key."\">".$value."</option>";
}
?>
</select>

Link to comment
https://forums.phpfreaks.com/topic/118247-solved-multiple/#findComment-608546
Share on other sites

No, I have a form like:

 

<select name="names" multiple="multiple">

  <option value="junk">Junk</option>

  <option value="trunk">Trunk</option>

</select>

 

If the user selects both values and then submits the form, how do I turn the values into an array than I can use foreach.

Link to comment
https://forums.phpfreaks.com/topic/118247-solved-multiple/#findComment-608599
Share on other sites

example:

 

<?php

// foreach loop
foreach ($_POST['names'] as $key => $val) {
   echo "$key $val <br />";
}

// echo individually
echo $_POST['names'][0]; // echo "junk"
echo $_POST['names'][1]; // echo "trunk"

?>

<br />
<form method = 'post' action = ''>
<!-- the select name needs to be an array -->
<select name="names[]" multiple="multiple">
  <option value="junk">Junk</option>
  <option value="trunk">Trunk</option>
</select>
<br /><input type = 'submit' value = 'submit'>
</form>

Link to comment
https://forums.phpfreaks.com/topic/118247-solved-multiple/#findComment-608608
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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