0

I have this array that I am needing to insert into the database. My below code does not work, I end up with the same values.

array(10) { [0]=>  array(1) { ["GymnastName"] => string(7) "ertwert"  }
            [1]=>  array(1) { ["GymnastName"] => string(6) "wergfb"  }
            [2]=>  array(1) { ["GymnastAge"] => string(8) "ewrtwert" }
            [3]=>  array(1) { ["GymnastAge"] => string(8) "dsfvsdtg" }
            [4]=>  array(1) { ["ParentsName"] => string(9) "werfgdsfv" }
            [5]=>  array(1) { ["ParentsName"] => string(9) "wetrgwerg" }
            [6]=>  array(1) { ["ParentsEmail"] => string(7) "erteqrt" }
            [7]=>  array(1) { ["ParentsEmail"] => string(6) "adfwer" }
            [8]=>  array(1) { ["ParentsPhone"] => string(7) "ertwert" }
            [9]=>  array(1) { ["ParentsPhone"]=> string(4) "qert" }
}

Here is my loop:

for ($i=0; $i<$l; $i++) {

    $name = $gymarray[$i];
    $age = $gymarray[$i];
    $parentname = $gymarray[$i];
    $parentemail = $gymarray[$i];
    $parentphone = $gymarray[$i];

    $db->insert statement here

Essentially I need to insert the records as GymnastName, GymnastAge, ParentsName, ParentsEmail, ParentsPhone.

What I end up with on the final code is:

array(1) {
["GymnastName"]=>
string(7) "ertwert"
}

array(1) {
["GymnastName"]=>
string(7) "ertwert"
}

array(1) {
["GymnastName"]=>
string(7) "ertwert"
}

array(1) {
["GymnastName"]=>
string(7) "ertwert"
} 

array(1) {
["GymnastName"]=>
string(7) "ertwert"
}
2
  • What is the content of $gymarray ? What is the value of $l ? What is the content of the first array, the final result ? Commented Jun 18, 2012 at 16:45
  • The content of $gymarray is the structure / array listed. $l = count($gymarray)/5; Commented Jun 18, 2012 at 16:50

1 Answer 1

2

I guess that you want to do something like

for ($i=0; $i<$l; $i) {

    $name        = $gymarray[$i]["GymnastName"];
    $age         = $gymarray[$i + 2]["GymnastAge"];
    $parentname  = $gymarray[$i + 4]["GymnastAge"];
    $parentemail = $gymarray[$i + 6]["ParentsEmail"];
    $parentphone = $gymarray[$i + 8]["ParentsPhone"];

    $db->insert statement here
}
Sign up to request clarification or add additional context in comments.

1 Comment

@ Luc - Thanks Luc, I appreciate your help and assistance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.