SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)

    inserting 2 tables same id

    Lets say I have two tables

    Table 1
    -----------
    tid (auto inc) | name | etc |

    Table 2
    ------------
    aid (auto inc) | tid | category |

    Now how do I, most effectively, add one to table and multiple to table 2?

    For example, say I have the data: yourname, body, category1, category2, catgory3.

    Then the tables should look like
    Table 1
    -----------
    1 | yourname | body

    Table 2
    ------------
    1 | 1 | category 1
    2 | 1 | category 2
    3 | 1 | category 3

    Probably simple, but I am stumpted. Thanks
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,247
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    1. insert the row to table1
    2. use mysql_insert_id() function to get the tid value that was assigned in 1.
    3. use this value for tid in table2
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Great things alot
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users


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
  •