ratgurrl Posted February 28, 2009 Share Posted February 28, 2009 I'd like to preface by saying that arrays and regex are not my fortes.... This time I am having issues with an array, and I can't wrap my brain around how to do what I need to do, even after looking at many examples... I have a multiple select field in a form... <select name="propExterior[]" size="5" multiple="multiple" id="propExterior"> <option value="Aluminum/Vinyl">Aluminum/Vinyl</option> <option value="Brick">Brick</option> <option value="Cedar">Cedar</option> <option value="Concrete">Concrete</option> <option value="Dryvit">Dryvit</option> <option value="Hardiboard">Hardiboard</option> <option value="Stucco">Stucco</option> <option value="Steel/Glass">Steel/Glass</option> <option value="Other">Other</option> </select> I (think) this should pass the array of selected items... if (isset($_POST['pricingSubmit'])) { $propExterior = $_POST['propExterior']; ... } Then, after all the variables are set from the posted form, I am formatting an email... ... $body = "\n\nProperty Information\n\n"; $body .= "Property Type: $propType\n"; $body .= "Property Address: $propAddress\n"; $body .= "Subdivision/Neighborhood: $propHood\n"; $body .= "Bedrooms: $numBedroom\n"; $body .= "Exterior: $propExterior\n"; ... So basically I need '$propExterior = Brick, Concrete, Stucco' (or whatever items are selected), so the line in the email will look like this... Exterior: Brick, Concrete, Stucco (or whatever items are selected). Any help would be much appreciated. I've officially hit a brick wall, and I'm getting more confused the more I look. ??? Many Thanks, Jennifer Quote Link to comment https://forums.phpfreaks.com/topic/147257-solved-setting-array-to-one-variable-to-display-later/ Share on other sites More sharing options...
RussellReal Posted February 28, 2009 Share Posted February 28, 2009 add me to MSN I actively help most of the people on my friends list with PHP and MySQL so you would fit in nicely.. I also have done few tutor jobs for money but I prefer to help for free. My name is Russell and my MSN is RussellonMSN [AT] hotmail.com also: try <?php print_r($_POST); ?> to see if your values r being sent, and the construct of the print_r will tell you how you should reference the values Quote Link to comment https://forums.phpfreaks.com/topic/147257-solved-setting-array-to-one-variable-to-display-later/#findComment-773030 Share on other sites More sharing options...
ratgurrl Posted February 28, 2009 Author Share Posted February 28, 2009 Thanks Right now.. if I echo $propExterior, it displays: Array Jen Quote Link to comment https://forums.phpfreaks.com/topic/147257-solved-setting-array-to-one-variable-to-display-later/#findComment-773034 Share on other sites More sharing options...
RussellReal Posted February 28, 2009 Share Posted February 28, 2009 <?php print_r($propExterior); ?> you will get something like.. Array ( [KEY] => VALUE [KEY] => VALUE [KEY] => VALUE ) Quote Link to comment https://forums.phpfreaks.com/topic/147257-solved-setting-array-to-one-variable-to-display-later/#findComment-773035 Share on other sites More sharing options...
Maq Posted February 28, 2009 Share Posted February 28, 2009 if(isset($_POST['pricingSubmit'])) { foreach($_POST['propExterior'] as $key => $value) { $propExterior .= $value . ", "; } echo $propExterior; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/147257-solved-setting-array-to-one-variable-to-display-later/#findComment-773036 Share on other sites More sharing options...
Philip Posted February 28, 2009 Share Posted February 28, 2009 <?php if(isset($_POST['pricingSubmit'])) { foreach($_POST['propExterior'] as $key => $value) { $propExterior .= $value . ", "; } echo $propExterior; } ?> Or just implode() <?php if(is_array($_POST['propExterior'])) $propExterior = implode(', ',$_POST['propExterior']); else $propExterior = $_POST['propExterior']; echo $propExterior ?> Quote Link to comment https://forums.phpfreaks.com/topic/147257-solved-setting-array-to-one-variable-to-display-later/#findComment-773039 Share on other sites More sharing options...
ratgurrl Posted February 28, 2009 Author Share Posted February 28, 2009 Maq, I love you! Thank you so much... you have prevented me from going completely bald. King, Thanks too! I had tried the implode (based on an example I had seen), but was messing it up somehow... I appreciate both of your suggestions and help! It is working now. Jennifer <3 Quote Link to comment https://forums.phpfreaks.com/topic/147257-solved-setting-array-to-one-variable-to-display-later/#findComment-773044 Share on other sites More sharing options...
Maq Posted February 28, 2009 Share Posted February 28, 2009 Maq, I love you! Thank you so much... you have prevented me from going completely bald. Jennifer You're welcome Although, you may want to use KingPhilip's solution because it will eliminate the last comma with the least amount of code. Quote Link to comment https://forums.phpfreaks.com/topic/147257-solved-setting-array-to-one-variable-to-display-later/#findComment-773046 Share on other sites More sharing options...
RussellReal Posted February 28, 2009 Share Posted February 28, 2009 I was tryna help her figure it out on her own Quote Link to comment https://forums.phpfreaks.com/topic/147257-solved-setting-array-to-one-variable-to-display-later/#findComment-773047 Share on other sites More sharing options...
ratgurrl Posted February 28, 2009 Author Share Posted February 28, 2009 I was tryna help her figure it out on her own I appreciate Russell, but I had already spent all of last night pulling my hair out - I usually wait until I get uber frustrated before asking for help. I had gotten so close (based on the examples above), but wasn't getting it to work. Appreciate all the help... Quote Link to comment https://forums.phpfreaks.com/topic/147257-solved-setting-array-to-one-variable-to-display-later/#findComment-773048 Share on other sites More sharing options...
Maq Posted February 28, 2009 Share Posted February 28, 2009 I was tryna help her figure it out on her own Yeah I see what you're saying, I only do that if kids are want answers to homework, and this doesn't look like HW. She was so close anyway... Quote Link to comment https://forums.phpfreaks.com/topic/147257-solved-setting-array-to-one-variable-to-display-later/#findComment-773050 Share on other sites More sharing options...
ratgurrl Posted February 28, 2009 Author Share Posted February 28, 2009 Ha! No homework here (Gosh, I wish!!). Working on a real estate broker site for my friend's mom. Quote Link to comment https://forums.phpfreaks.com/topic/147257-solved-setting-array-to-one-variable-to-display-later/#findComment-773054 Share on other sites More sharing options...
RussellReal Posted February 28, 2009 Share Posted February 28, 2009 the MSN add is always on the table incase you need any help in the future that way you don't need to rip your hair out for 10 hours Quote Link to comment https://forums.phpfreaks.com/topic/147257-solved-setting-array-to-one-variable-to-display-later/#findComment-773062 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.