Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 18th, 2004, 01:45 AM
Registered User
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Parsing a Listbox Array

I have a form that uses Multiple Listbox to allow the user to choose multiple selections. I need to parse these selections to then email the information.

Code snippet:
=============================
<select name='select[]' size='5' multiple>");
   do {
      print("<option value='");
         echo $row_Recordset1['catagory']; print("'>");
         echo $row_Recordset1['catagory']; print("</option>");
      } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
           $rows = mysql_num_rows($Recordset1);
              if($rows > 0) {
                mysql_data_seek($Recordset1, 0);
                $row_Recordset1 = mysql_fetch_assoc($Recordset1);
      }
</select>

Then this is the code snippet for creating and mailing the information:
====================
$re = "Contact Form Entry";
$list = implode(",", $select);
$msg = "FROM: $_POST[name]
      $_POST[company]
      $_POST[address]
      $_POST[city], $_POST[state] $_POST[zip]
      Phone: $_POST[phone] Fax: $_POST[fax]
      $_POST[email]

      $_POST($list)
$_POST[msg]";
$headers .= "From: $_POST[webmail] \r\n";
$myemail = "$youremail";
mail($myemail,$re,$msg, $headers);
============================================

This is the output of an email:
================================
FROM: admin

      ABC Company Name
      123 Street Address
      SomeCity, ST 55555

      Phone: 555-123-4567 Fax: 555-123-4567
      [email protected]

      Array(Accuride,Layed Up Panels,Acrylic Sheets)

      Message box in put

=============================
The problem is that the array prints like this:
'Array(Accuride,Layed Up Panels,Acrylic Sheets)'
I can live with it but it would be nicer to have the items list this:
Accuride,Layed Up Panels,Acrylic Sheets

Thanks for any help.


 
Old December 20th, 2004, 04:20 PM
Authorized User
 
Join Date: Dec 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to peg110
Default

Don't use $_POST($list) just use $list Once you IMPLODE it you have created a SINGLE string seperated by a comma (in this case). So you only need to echo the SINGLE variable $list Besides that $_POST($list) would be incorrect anyway, you should use SQUARE brackets with the arrays.

Paul Gardner
------------------
PHP-LIVE help
Via Web @ http://www.mnetweb.co.uk/irc
Via IRC Client pgardner.net:6667
room #PHP
 
Old December 21st, 2004, 02:30 PM
Registered User
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the help. Works like it should now!!






Similar Threads
Thread Thread Starter Forum Replies Last Post
parsing an array chris1012 Java Basics 2 January 22nd, 2008 04:05 PM
multiple Listbox values in another listbox terryv Excel VBA 0 June 27th, 2007 07:01 AM
ListBox & Array Kenny Alligood Access VBA 5 February 16th, 2004 11:25 AM
Copy Items From An Array Into A ListBox? Adam166 VB.NET 2002/2003 Basics 2 November 22nd, 2003 11:01 AM
I'm back :) Listbox var from listbox MichaelTJ .NET Web Services 2 October 21st, 2003 07:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.