Jump to content

multidimensional arrays


nevsi79

Recommended Posts

my script worked, i was  jumping on my bed with joy, then I modified and now it does not work I just can't see why?!!!

 

here's my form:

http://geeks-fix.co.uk/wforms/form.html

 

now this is my code:

 

<?php

$cnt = count($_POST['wf_Relatives1']); 
// any field that 
//repeats(if you want to know how many repeats there are)

$fieldset = $_POST['wf_Relatives1']; 
$field = $_POST['wf_FirstName'];
//echo "$field";
$field2 =$_POST['wf_LastName'];
//echo "$field";
$field3 =$_POST['wf_BirthDate2'];
//echo "$field";

foreach ($fieldset as $c) {
	while (list($k, $v) = ($c)) {
	  echo "$k ... $v <br/>";
	  }
	}   

	   ?>

 

The first time it worked definitely with the $fieldset and after I added 3 times (first name, last name, dob) in the form, it did output the following:

 

0 ... some first name A

1 ... some first name B

2 ... some first name C

0 ... some last name A

1 ... some last name B

2 ... some last name C

0 ... some dob A

1 ... some dob B

2 ... some dob C

 

but now it is not working, instead prints out this:

Warning: Invalid argument supplied for foreach() in /home2/nevsi79/public_html/wforms/firstoutput.php on line 15

 

Can anyone see where the problem is:

 

I wonder how they are doing it here: http://www.formassembly.com/wForms/v2.0/documentation/examples/repeat.html

 

 

 

Link to comment
Share on other sites

Foreach expects an array. You're giving it a string.

 

Yes but it worked the first time,

 

I found this in my book:

 

foreach ($fieldset as $c) {
	while(list($k, $v) = each ($c)) {
	echo "k ... $v <br/>";
	}
}

 

 

Anyhow, you might understand me better if I do the following (print_r the fields as they are arrays even if I do not repeat them with the repeat js behaviour as I added [] to the names of each field):

 

<?php

$cnt = count($_POST['wf_Relatives1']); 
// any field that 
//repeats(if you want to know how many repeats there are)

$fieldset = $_POST['wf_Relatives1']; 
$field = $_POST['wf_FirstName'];
print_r($field);
echo"<br/>";
$field2 =$_POST['wf_LastName'];
print_r($field2);
echo"<br/>";
$field3 =$_POST['wf_BirthDate2'];
print_r($field3);
echo"<br/>";

//foreach ($fieldset as $c) {
	//while(list($k, $v) = each ($c)) {
	//echo "k ... $v <br/>";
	//}
//}

	   ?>

 

and then I get this output:

 

Array ( [0] => some first name A [1] => some first name B [2] => some first name C )

Array ( [0] => some last name A [1] => some last name B [2] => some last name C )

Array ( [0] => some DOB A [1] => some DOB B [2] => some DOB C )

 

I do not insist in organising them in a multidimensional array, but my final go is t put them in mysql table.

 

MySql table will basically have 3 columns: first name, last name, DOB

 

and I want A, B & C to be different entries i.e. rows in my table, if that makes sense at all?

 

Can anyone help, please?

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.