Jump to content

reading out array


stijn0713

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.