Inserting data into table issue/question

Discussion in 'MySQL' started by Marius90, Mar 17, 2019.

  1. #1
    I have a table database where i store some userids and productids. Every time i insert i need to add userid in a field, productid in the other field and go insert. Doing this in the table it will create a row/separate rows with the data i insert.
    Is it possible to insert multiple productids for the same userids at the same time creating multiple rows in the table for the same userid?
    I add userid in the field, then i add productid1;productid2;productid3 in the other field and on the table upon insert to create multiple rows with the same userid(i used) for the different productids ?
    Sorry if i can't explain it better... Thank you.
     
    Marius90, Mar 17, 2019 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,830
    Likes Received:
    4,541
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Are you trying to work out how to build a form to capture the info or how to write the insert statements?
     
    sarahk, Mar 17, 2019 IP
  3. mmerlinn

    mmerlinn Prominent Member

    Messages:
    3,197
    Likes Received:
    819
    Best Answers:
    7
    Trophy Points:
    320
    #3
    How about showing us what you have tried already? Then showing us what you are trying to do.
     
    mmerlinn, Mar 17, 2019 IP
  4. Marius90

    Marius90 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    I am trying to insert multiple statements at the same time for the same userid, but to be inserted on different rows in the table, not the same row
     
    Marius90, Mar 18, 2019 IP
  5. mmerlinn

    mmerlinn Prominent Member

    Messages:
    3,197
    Likes Received:
    819
    Best Answers:
    7
    Trophy Points:
    320
    #5
    You either need to insert them manually one at a time or write a program/function to insert them automatically one at a time.
     
    mmerlinn, Mar 18, 2019 IP
  6. Marius90

    Marius90 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #6
    OK. I understand I can't do them the way i want :)
     
    Marius90, Mar 18, 2019 IP
  7. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #7
    Try this:

    insert into table
    (id, userID, productID) values
    ('', '123', '111'),
    ('', '123', '222'),
    ('', '123', '333'),
    and so on...

    userid=123 is the same for each entry, productID changes for each row.

    I hope I understood your question properly...
     
    JEET, Mar 30, 2019 IP