Jump to content

reading out array


stijn0713

Recommended Posts

my $_POST array would look something like this:

 

Array ( [hf_1] => stijn03@hotmail.com [cb_1] => on [bedrag_1] => [hf_2] => jan.janssens@hotmail.com [cb_2] => on [bedrag_2] => [hf_3] => jozefien.vanlo@gmail.com [bedrag_3] => [hf_4] => paolakingofbelgium@belgie.be [bedrag_4] => [hf_5] => lorejarrin@gmail.com [bedrag_5] => [hf_6] => wouter.verbeek@hotmail.com [bedrag_6] => [hf_7] => stijn09@hotmail.com [bedrag_7] => [hf_8] => stijn00@hotmail.com [bedrag_8] => [hf_9] => stijn05@hotmail.com [bedrag_9] => [hf_10] => linda.dieterickx@gmail.com [bedrag_10] => [hf_11] => jos.gijsen@gmail.com [bedrag_11] => [hf_12] => joss.gijsen@gmail.com [bedrag_12] => [hf_13] => josss.gijsen@gmail.com [bedrag_13] => [hf_14] => jossss.gijsen@gmail.com [bedrag_14] => [hf_15] => trien.vandooren@yahoo.be [bedrag_15] => [hf_16] => osazee.efe@knappegast.be [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
Share on other sites

I'd reorganise the form so you had

 

Array
(
    [hf] => Array
        (
            [1] => stijn03@hotmail.com
            [2] => jan.janssens@hotmail.com
            [3] => .vanlo@gmail.com
        )

    [cb] => Array
        (
            [1] => on
            [2] => 
            [3] => on
        )

    [bedrag] => Array
        (
            [1] => 
            [2] => 
            [3] => 
        )

    [submit] => nodig respondenten uit
)

Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.