I've been searching for days, now i got to ask here ... I have 1 array which i'd like to insert into sql .. however the structure of the array makes it difficult.
$the_array = [
[
"3_Bachelor",
[
3 => "English",
4 => "German"
]
],
[
"3_Master",
[
1 => "Marketing",
2 => "Accountancy"
]
]
];
Here is the first draw, not working :
$id = "3";
$sql = "INSERT INTO users (id,i d_training_key ,training_lectures)
VALUES (:id, :id_training_key, :training_lectures)";
$stmt= $pdo->prepare($sql);
foreach ($the_array as $lec => $l) {
foreach ($l as $a) {
$stmt->execute($l[0], $id, $a);
}
}
The difficult part lays in the array, in the array, in array ... You see what i mean ?
The DB looks like and "English" and "German" should be in one single line with 'id' and 'id_training_key' repeated on each line: id | id_training_key | training_lectures
Do you guys have any idea or hint ? If you thing that the array should be restructured, what's your opinion ?
Thanks a lot !
training_lectures- do you want English and German concatenated as a string, a separate line inserted per, or...?training_lecturesshould be inserted as separate lines. But if a string with a delimiter is the only solution, then I'd be okay with it. Do you think that the current structure of the array is appropriate for such query ?