We help IT Professionals succeed at work.

Passing multiple values from Select list

1,466 Views
Last Modified: 2013-12-12
I have a select list where the user can select multiple values. When i try to retrieve the data on the next page, only one value passes.

How can I store all of the selected values in one variable?
<select NAME="search" size="32" MULTIPLE style = "width:170px"  >
              <OPTION VALUE="Open Mondays" >Open Mondays</OPTION>
              <OPTION VALUE="Breakfast" >Breakfast</OPTION>
              <OPTION VALUE="Brunch" >Brunch</OPTION>
              <OPTION VALUE="Buffet" >Buffet</OPTION>
              <OPTION VALUE="Fireplace" >Fireplace</OPTION>
              <OPTION VALUE="Historic Building" >Historic Building</OPTION>
              <OPTION VALUE="Outdoor dining">Outdoor dining</OPTION>
              <OPTION VALUE="Waterfront" >Waterfront</OPTION>
</select>
 
next page I am doing this:
 
<? $search = $_POST['search'];
 
 
echo $search;
 
 
 
 ?>

Open in new window

Comment
Watch Question

Commented:

<select NAME="search[]" size="32" MULTIPLE style = "width:170px"  >
              <OPTION VALUE="Open Mondays" >Open Mondays</OPTION>
              <OPTION VALUE="Breakfast" >Breakfast</OPTION>
              <OPTION VALUE="Brunch" >Brunch</OPTION>
              <OPTION VALUE="Buffet" >Buffet</OPTION>
              <OPTION VALUE="Fireplace" >Fireplace</OPTION>
              <OPTION VALUE="Historic Building" >Historic Building</OPTION>
              <OPTION VALUE="Outdoor dining">Outdoor dining</OPTION>
              <OPTION VALUE="Waterfront" >Waterfront</OPTION>
</select>
 
next page I am doing this:
 
<? $search = $_POST['search'];
 
 
print_r($search);
//$search is now an array and must be treated as one
 
 
 
 ?>

Open in new window

Top Expert 2007

Commented:

Author

Commented:
this is the result I get

Array(    [0] => Live Music    [1] => Good Wine List    [2] => Views)

what I need to do is store the data in a variable and use that to search a table in a database. is there anyway to make it appear like this instead?

Live Music , Good Wine List    ,Views

Commented:
echo implode($search, ", ");

Author

Commented:
I get


Warning:  implode() [function.implode]: Invalid arguments passed
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.