[solved] Obtaining multiple values from a list menu

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

[solved] Obtaining multiple values from a list menu

Post by hame22 »

Hi I have a form page containing a select menu (id = "salary") whereby the user can select multiple values.

The form data is then posted to my 2nd page.

What I am trying to do is then get this posted salary data, if I was only sending one value across I would enter $salary = $_POST['salary'] however what is the terminology when posting multiple values?

Thanks in advance
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Post by Rovas »

You can send multiple data using POST or GET but you have to name your data differently ex data1, data2 i.e.

Code: Select all

$_POST['data1'] != $_POST['data2']
But try this code:

Code: Select all

//your code
echo "<select>";
echo "<option value='2.php' select='selected'>Default value</option>";
echo "<option  value='2.php?salary=1'>10000-20000</option>";
echo "<option value='2.php?salary=2'>21000-3000</option>";
echo "</select>"
//etc, etc, etc
//In the second page
if(is_numeric($_POST) && $_POST['salary']==2) 
{
//your code for that case
}
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

Post by hame22 »

sorry i dont't think I explained that very well.....

what Iam trying to do is to send multiple values from ONE dropdown:

Code: Select all

<select name="salary" size="5" multiple="multiple">
              <option value="1">10,000</option>
              <option value="2">20,000</option>
              <option value="3">30,000</option>
            </select>
so this dropdown lets me select multiple values from it (not just the one)

What I am having trouble is assigning the multiple values on the 2nd page once it has been posted.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

<select name="salary[]" size="5" multiple="multiple">
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

Post by hame22 »

yeah that is spot on, just found the same answer myself, thanks!
Post Reply