0

I have arrays within an array and I want to loop through each item of the nested arrays and put them into different mysql columns. There is a limit of 3 entries per array, and I need $workexp_array_t to go into the work experience column, the $credentials_array_t items to go into the credentials column etc.

The problem I'm having is that using these nested foreach loops it just places the first letter of the entry into the column instead of the proper entry. How can I get each array items to go into their proper column? Do I really need to set up separate tables for each thing (ie. education experience, credentials, work experience, etc.)?

    $tutor_background = array($workexp_array_t, $credentials_array_t, $education_array_t, $extra_array_t);

foreach ($tutor_background as $entry) {
    foreach ($entry as $background) {
        $query = "INSERT INTO tutor_background (login_value, work_history, credentials, education_history, extra_skills) VALUES ('{$_SESSION['login_value']}', '{$background[0]}', '{$background[1]}', '{$background[2]}', '{$background[3]}')";
        $process_query = mysql_query($query);
    }
}
2
  • Can you show us how your array is setup with a print_r($tutor_background) Commented Dec 8, 2012 at 0:53
  • is each $background a string? that would explain why it's only entering one character. either that, or the column is set to varchar(1) Commented Dec 8, 2012 at 0:53

1 Answer 1

1

Going to take a guess here and say you only need one foreach.

$tutor_background = array($workexp_array_t, $credentials_array_t, $education_array_t, $extra_array_t);

foreach ($tutor_background as $entry) {
        $query = "INSERT INTO tutor_background (login_value, work_history, credentials, education_history, extra_skills) VALUES ('{$_SESSION['login_value']}', '{$entry[0]}', '{$entry[1]}', '{$entry[2]}', '{$entry[3]}')";
        $process_query = mysql_query($query);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

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.