SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2002
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL Question for the newbe

    Hi guys:

    That's me again. It may stupid enough but here is the problem I have with MySQL. I know that you can create join and anyone who starts to deal with MySQL knows it is the case when two tables are used together. I got that far long ago. However I got stuck on the thing that comes before you can create the join. Let's say you you have two tables - that has interelated info in them. My question is - let's say I want to ad a record and I need some pieces to be written two one table and some written two another table. How do I do that in such way that I can tie them together with a join later on?

    For example in Kevin Yank's book he creates two tables
    Jokes (ID, JokeText, JokeDate, AID) and Authors (ID, Name, EMail). So whenever someone ads a joke, info is written to both tables where AID of table jokes have IDs that can be found in ID column of Authors. How would you do that?

    Can anyone give a piece of code with some kind of explanation?

    Thanks a million, guys

    Peace, dude

  2. #2
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it is not mysql question, it is database design question you ask. You should go to base a little and read design tutorials before going further.

    Table 1
    tb_id
    tb_text_field
    tb_numeric_field


    table 2
    tb2_id
    tb2_somefield
    tb_id <-------------- connection to table 1

    or
    table connection
    tb_id <-------------- connection to table 1
    tb2_id <-------------- connection to table 2

    table 3
    tb2_id
    tb2_somefield

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    are you asking about how to get the auto_increment value back from the database after having inserted a new row in order to use that value in another table?

    use the mysql_insert_id() function

    rudy


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
  •