Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-10-2012, 06:19 AM   PM User | #1
john6
New Coder

 
Join Date: Sep 2012
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
john6 is an unknown quantity at this point
Question $_POST a 2D array?

I have an unknown number of check-boxes in a form (generated by php) that the end-user will tick. How can I do 2D arrays for that?

I.e.

OptionA:
[ ] Tickbox 1
[ ] Tickbox 2
[ ] Tickbox 3

OptionB:
[ ] Tickbox 1
[ ] Tickbox 2
[ ] Tickbox 3

And then get the values like:

_POST[OptionA][1,2,3,4,5..]
_POST[OptionB][1,2,3..]

etc.?

Thanks!

Last edited by john6; 10-10-2012 at 06:51 AM..
john6 is offline   Reply With Quote
Old 10-10-2012, 05:33 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,498
Thanks: 18
Thanked 362 Times in 361 Posts
sunfighter is on a distinguished road
easier than me trying to explain: http://www.w3schools.com/html/html_forms.asp
sunfighter is offline   Reply With Quote
Old 10-10-2012, 05:57 PM   PM User | #3
Len Whistler
Senior Coder

 
Len Whistler's Avatar
 
Join Date: Jul 2002
Location: Vancouver, BC Canada
Posts: 1,323
Thanks: 26
Thanked 100 Times in 100 Posts
Len Whistler is on a distinguished road
You use a foreach loop. The example below is a quick one so there might be syntax errors. You can also assign the output to variables, instead of echoing it out.

PHP Code:
$array _POST['OptionA']; // 0,1,2,3,4,5,6 .........

foreach ($array as $value) {
echo 
"$value";



-----
__________________
Leonard Whistler
Len Whistler is offline   Reply With Quote
Old 10-10-2012, 08:14 PM   PM User | #4
Wuteverx1972
New Coder

 
Join Date: Aug 2010
Posts: 53
Thanks: 6
Thanked 1 Time in 1 Post
Wuteverx1972 is an unknown quantity at this point
Try using an array + foreach loop:

PHP Code:
$arr = array ('options' => $_POST['option1'], $_POST['option2'],$_POST['option3'], $_POST['option4']); 
$output"";
foreach (
$arr as $arr) {    
 
$value .= $arr.", ";
}
echo 
$output
You can store the $output into your database, however it may be difficult to analyze the data after... There is better method to store multiple values for data analysis but that's my 2 cents.
Wuteverx1972 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:33 PM.


Advertisement
Log in to turn off these ads.