Results 1 to 4 of 4

Thread: Submitting POST array to MySQL?

  1. #1
    Join Date
    Apr 2008
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Submitting POST array to MySQL?

    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
    • person_id
    • name

    Country
    • country_id
    • country_name

    Actor_map
    • movie_id
    • person_id

    Director_map
    • movie_id
    • person_id

    Country_map
    • movie_id
    • country_id



    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?

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    I would use a server-side language such as php to process the information, before you submit / update the DB

  3. #3
    Join Date
    Apr 2008
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Well, that's why I posted this in the PHP forum. :P
    I need some help with the code...

  4. #4
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    i am not sure what the numerical index is next to the values you have in the example, but first you would need to gather all of your values, from the form... then you would split out the movie information from the actor information.
    then you would check if the movie existed. if it does update the values, if it doesn't then insert it into the database
    then you would loop through the actors, see if they exists, if they do great, if not insert it.
    then you would do 1 final step by grabbing the actor id and the movie id and insert it into the reference table

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •