473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Retrieve array from FORM List of values?

Hi folks,

Trying to fill in a gap in my understanding of php, and so this is rather
newbish:

I have created a form where a user selects 2 items from a list of 8 values.
That form field is called "choices" and returns a value to the php file as
$choices. This form posed no problem when I only allowed a single item to be
selected, but the client now needs to have 2 items selected at a time.

The problem I'm having is that I don't know how to turn the multiple
selections on the form in to an array. I thought the $choices variable
would automatically become an array, but
Using
for ( $i = 0; $i<2; $i++ )
echo "$choices[$i] "; only returns the first two letters of the last selected item value.

And
foreach($choices as $articles)
echo $articles. ' ' ;


Returns an invalid argument.

While echo $choices returns the second item selected in the list, but not
the first.
It appears that the variable is replacing the first item selected with the
second rather than returning an array.

Any help appreciated.
Thanks
Jeff

~~~~~~~~~~~~
Jefferis Peterson, Pres.
Web Design and Marketing
http://www.PetersonSales.com

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 17 '05 #1
2 2356
Jefferis NoSpamme wrote:
That form field is called "choices" and returns a value to the php
file as $choices. This form posed no problem when I only allowed a
single item to be selected, but the client now needs to have 2 items
selected at a time.


Read the fine manual... In your form, you need to set the name of the
item as NAME="choices[]", and this way PHP receives it as $choices
that is an array. Quite simple actually :)

--
Markku Uttula

Jul 17 '05 #2
Thank You. I have 3 books I poured through, but none talked about using [ ]
in an html form to transmit the multiple selections as an array. They only
talked about iterating arrays from defined arrays.

Thanks again,
Jeff
On 3/5/05 9:55 PM, in article Om*****************@reader1.news.jippii.net,
"Markku Uttula" <ma***********@disconova.com> wrote:
Read the fine manual... In your form, you need to set the name of the
item as NAME="choices[]", and this way PHP receives it as $choices
that is an array. Quite simple actually :)

--
Markku Uttula


~~~~~~~~~~~~
Jefferis Peterson, Pres.
Web Design and Marketing
http://www.PetersonSales.com

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: wk6pack | last post by:
Hi, I have a form with the following elements: first form <input type='text' name='addr1' value='1223 westward'> <input type='text' name='addr2' value='12 admirals rd'> <input type='text'...
5
by: Andrew V. Romero | last post by:
At work we have an excel file that contains the list of medications and their corresponding strengths. I would like to save the excel file as a text list and paste this list into a javascript...
3
by: niftyhawk | last post by:
Hi All, I have a php page say "abc.php" generating the following HTML. I am posting the form action to another php page say "TestCheckbox.php". How do I retrieve in "TestCheckbox.php" which...
6
by: Daz | last post by:
Hi everyone. Firstly, I apologise if this i not what you would call a PHP problem. I get quite confused as to what lives in which realm, so if this shouldn't be posted here, please suggest where...
1
by: assgar | last post by:
Hi I need help solving a porblem. I have a form that displays a checkbox, service code, description and dropdown with fees on each row. The fee_money and unit array only returns a...
4
by: Matt | last post by:
I am no JavaScript guru so please bear with me and be as detailed as possible with your response. I thank you in advance. I have an ASP page that contains form elements. I also have an inline...
10
by: SM | last post by:
Hello I'm trying to create a multi dimensional array in JavaScript, but after some reading i still can't figure out how to apply it to my model. Here it is: I have a list A and for each item...
2
by: chirag1989 | last post by:
i have created an arry of text box now i want to retrieve the values of each text box so as to insert them in data base can anyone help how can i retrieve the values of array of textbox and store...
4
by: TechnoAtif | last post by:
Hi ALL I have entered some array values using checkboxes into mysql database through a form. Next iam creating a searchpage where all those cateogories inserted through checkboxes has to be...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.