Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array problem - not seeing all selections.

Status
Not open for further replies.

towntopic

Technical User
Joined
May 15, 2003
Messages
103
Location
US
I didn't want to have to ask this but I can't seem to get it working. I'm really new to PHP and have run into a problem. I have a form with a multiple select that is only passing the last value through. I searched through this forum and found some info, but I still haven't resolved it. Here's what I have in the form.

<select name="24x7Thoughts[]" multiple>
<option selected>- Select Option(s) -</option>
<option>Option A</option>
<option>Option B</option>
<option>Option C</option>
<option>Option D</option>
</select>


Then on the script I have...

$TwentyFourThoughts = $HTTP_POST_VARS['24x7Thoughts'];

and then later...
$mailcontent = $mailcontent."TWENTY FOUR SEVEN SUPPORT\n\n"
." ".$TwentyFour.", ".$TwentyFourExtra.", ".$TwentyFourThoughts."\n\n";

I apologize in advance if this is a really easy fix. Thanks for any help.
 
When a user's selections from that form are transmitted to the server, $_POST['24x7Thoughts'] will itself be an array.

Your code doesn't seem to account for that.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I understand that I'm not going to get a free lunch, sorry to waste your time.
 
Make use of foreach loop to parse thru the array and make a string to collect all the values selected.

Code:
$TwentyFourThoughts = "" ;
foreach ( $HTTP_POST_VARS["24x7Thoughts"] as $options ) {
   $TwentyFourThoughts .= $options."," ;
}

$TwentyFourThoughts = substr( $TwentyFourThoughts,0,strlen($TwentyFourThoughts) - 1 ) ;



--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top