stijn0713 Posted July 15, 2012 Share Posted July 15, 2012 my $_POST array would look something like this: Array ( [hf_1] => [email protected] [cb_1] => on [bedrag_1] => [hf_2] => [email protected] [cb_2] => on [bedrag_2] => [hf_3] => [email protected] [bedrag_3] => [hf_4] => [email protected] [bedrag_4] => [hf_5] => [email protected] [bedrag_5] => [hf_6] => [email protected] [bedrag_6] => [hf_7] => [email protected] [bedrag_7] => [hf_8] => [email protected] [bedrag_8] => [hf_9] => [email protected] [bedrag_9] => [hf_10] => [email protected] [bedrag_10] => [hf_11] => [email protected] [bedrag_11] => [hf_12] => [email protected] [bedrag_12] => [hf_13] => [email protected] [bedrag_13] => [hf_14] => [email protected] [bedrag_14] => [hf_15] => [email protected] [bedrag_15] => [hf_16] => [email protected] [bedrag_16] => [submit] => nodig respondenten uit ) so, in there, a hidden field for emails, a checkbox with possibility of on/ off and an amount textfield. the checkbox contains at the back the id of the person that is either selected or not. now, i should firstly, loop through the array to see any values are 'on' secondly, fetch the amount and email of the persons for the keys that have the same id . I came up with this script, but there are still errors in it and i can't seem to find them. if(!empty($_POST['submit'])){ $hideform2 = 1; foreach($_POST as $key => $value){ if ($value == 'on'){ $id_respondent_on = trim($key, 'cb_'); } while(is_numeric($id_respondent_on)){ foreach($_POST as $key => $value){ if ($id_respondent_on == trim($key, 'hf_')){ $email_respondent_on = $value; } if ($id_respondent_on == trim($key, 'bedrag_')){ $bedrag_respondent_on = $value; echo $id_respondent_on; echo '<BR>'; echo $email_respondent_on; echo '<BR>'; echo $bedrag_respondent_on; echo '<BR>'; } } } } } Any suggestions? Link to comment https://forums.phpfreaks.com/topic/265700-reading-out-array/ Share on other sites More sharing options...
Barand Posted July 15, 2012 Share Posted July 15, 2012 I'd reorganise the form so you had Array ( [hf] => Array ( [1] => [email protected] [2] => [email protected] [3] => [email protected] ) [cb] => Array ( [1] => on [2] => [3] => on ) [bedrag] => Array ( [1] => [2] => [3] => ) [submit] => nodig respondenten uit ) Link to comment https://forums.phpfreaks.com/topic/265700-reading-out-array/#findComment-1361641 Share on other sites More sharing options...
stijn0713 Posted July 15, 2012 Author Share Posted July 15, 2012 Ofcourse, that makes sense . I'll try that first. Btw, how do you do it, my arrays are never printed that way. Link to comment https://forums.phpfreaks.com/topic/265700-reading-out-array/#findComment-1361646 Share on other sites More sharing options...
stijn0713 Posted July 15, 2012 Author Share Posted July 15, 2012 I was thinking, maybe i shouldn't do that, because actually, then i'm loosing information. The difference is that now, the cb_1, this 1 corresponds to the id of the user in my database. So i can also perform a query, if needed, otherwise, i won't be able to do it. ** oeps, too fast written, my bad, i get it. Link to comment https://forums.phpfreaks.com/topic/265700-reading-out-array/#findComment-1361649 Share on other sites More sharing options...
Barand Posted July 15, 2012 Share Posted July 15, 2012 Just name your form fields cb[$id], hf[$id] etc. Link to comment https://forums.phpfreaks.com/topic/265700-reading-out-array/#findComment-1361671 Share on other sites More sharing options...
stijn0713 Posted July 15, 2012 Author Share Posted July 15, 2012 Jup, i got it, thanks. But i meant the layout of your arrays, it's printed so that the levels are more clear. But i found that also. Thank for the suggestions! Link to comment https://forums.phpfreaks.com/topic/265700-reading-out-array/#findComment-1361676 Share on other sites More sharing options...
Barand Posted July 15, 2012 Share Posted July 15, 2012 Once your arrays are in that format <?php foreach (array_keys($_POST['cb'],'on') as $k) { echo $k.'<br />'; echo $_POST['hf'][$k].'<br />'; echo $_POST['bedrag'][$k].'<br /><br />'; } ?> Link to comment https://forums.phpfreaks.com/topic/265700-reading-out-array/#findComment-1361678 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.