I have a quite messy POST array (coming from a FORM) I want to nicely submit to a DB.
The array could at best look like this (although the order can be different, and the numbering is not necessarily consistent)
[title0] => Iron Man
[year1] => 2008
[country2] => US
[director3] => Jon Favreau
[genre4] => Sci-Fi
[genre5] => Action
[genre6] => Adventure
[actor7] => Robert Downey Jr.
[actor8] => Jeff Bridges
[actor9] => Gwyneth Paltrow
[actor10] => Terrence Howard
[runningtime11] => 126
I want to put this into a DB that looks like this (I think)
Movie
- movie_id
- title
- year
- runningtime
Persons
Country
Actor_map
Director_map
Country_map
And I want to account for possible existing values, ie. if person "Robert Downey Jr." already exists (either as Director or Actor), don't insert this as a new value, only update the links.
My first idea is as follows:
Code:
Parse the array element by element
Make a Switch/Case and sort the elements belonging together into a new array (one array per 'category')
(Somehow) add the new arrays to the DB
However, I feel that this is not very efficient, and I also have a little trouble entering the info into the database (bearing in mind not to duplicate values).
Any help?
Bookmarks