pthurmond Posted November 11, 2006 Share Posted November 11, 2006 Ok, so I have a list of dynamically generated items that is using an array to record each value to be processed by the next script.I would like to know if this array will only contain the values of the checkboxes that were checked, or will it contain the values of all the generated checkboxes, regardless of whether or not it was checked?I think it will only contain the values of the checked checkboxes, but I want to be sure.Here is the code:[code]echo '<td width="25"><input name="' . $event[] . '" type="checkbox" value="' . $value . '"></td>';[/code]Also I will be processing it as an array in the processing script, will this work?:[code]foreach($_POST['event'] as $key => $val){ $events[$key] = $val; }[/code]Thanks again for the help,Patrick Quote Link to comment Share on other sites More sharing options...
Skatecrazy1 Posted November 11, 2006 Share Posted November 11, 2006 Only posts values of checked boxes. Quote Link to comment Share on other sites More sharing options...
toplay Posted November 11, 2006 Share Posted November 11, 2006 I think you meant to use event[] as in this way:echo '<td width="25"><input name="event[]" type="checkbox" value="', $value, '"></td>';in order to access them this way: $_POST['event'][0], $_POST['event'][1], etc. Quote Link to comment Share on other sites More sharing options...
pthurmond Posted November 11, 2006 Author Share Posted November 11, 2006 Thank you for all your help, however the post by toplay confuses me a bit.First off I am guessing that I don't need to echo event[] outside the string of html.Secondly are you sure for the value you don't mean this:[code] echo '<td width="25"><input name="event[]" type="checkbox" value="' . $value . '"></td>';[/code]Third, can I still use the foreach() loop? And if so, how exactly does it work for a multi-dimensional array?Thanks,Patrick Quote Link to comment Share on other sites More sharing options...
Nhoj Posted November 11, 2006 Share Posted November 11, 2006 [code] foreach ($_POST['event'] as $key => $value){ echo $_POST['event']; }[/code] Quote Link to comment Share on other sites More sharing options...
pthurmond Posted November 12, 2006 Author Share Posted November 12, 2006 So would this work just as well?[code]foreach($_POST['event'] as $key => $val){ $events[$key] = $_POST['event']; }[/code]I am trying to get an array of values. This array will later be converted into a string of comma separated values with the implode function.Thanks,Patrick Quote Link to comment Share on other sites More sharing options...
Nhoj Posted November 12, 2006 Share Posted November 12, 2006 It looks like it would work from my view....try giving it a whirl on a test page and at the end print the entire array with this to see if it works:[code]echo "<pre>";print_r ($events);echo "</pre>";[/code] Quote Link to comment Share on other sites More sharing options...
toplay Posted November 12, 2006 Share Posted November 12, 2006 [quote author=pthurmond link=topic=114670.msg466646#msg466646 date=1163288644]Thank you for all your help, however the post by toplay confuses me a bit.First off I am guessing that I don't need to echo event[] outside the string of html.Secondly are you sure for the value you don't mean this:[code] echo '<td width="25"><input name="event[]" type="checkbox" value="' . $value . '"></td>';[/code]Third, can I still use the foreach() loop? And if so, how exactly does it work for a multi-dimensional array?Thanks,Patrick[/quote]1) Right (if I understand your question).2) You can use the period as a concatenation character in the echo, however, the echo is a PHP language construct and you can use commas to seperate values.3) Yes, you can use foreach(). Example:[code=php:0]foreach($_POST['event'] as $key => $val){ echo 'Array index: ', $key, ' Value: ', $val; }[/code]So, if you used this: echo '<td width="25"><input name="event[]" type="checkbox" value="1"></td>';Then it would display:Array index: 0 Value: 1 Quote Link to comment 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.