SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Home.
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation You read this now!

    This is a total novice, total newbie, total loser of an enquiry.

    I need the tables in my database to be linked through one-to-many relationships, only I don't know how...

    For example, I have
    Table one, Field A
    Table two, Field A

    When I add records to Field A in Table One, I want Field A in Table Two to update with the same data.

    I'm using MySQL CC and MySQL Front at the moment and I can't see how to do it. I created Field A in both tables, with the same properties in each.. and that's as far as I can see to go..

    It's probably staring me right in the face, but my dumb *** is just too dumb. I'm prepared to download other software if anyone can recommend anything that will make it easier.

    Please assist...

    Thanks.
    I AM NOT SENDING SUBLIMINAL MESSAGES.

    Stuff.

  2. #2
    SitePoint Guru
    Join Date
    Feb 2004
    Location
    Oregon
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    then add them to both tables with the same query.

    are the id's the same or what is linking those 2 tables together?
    success is not by chance, it is by choice.

  3. #3
    SitePoint Enthusiast rjahrman's Avatar
    Join Date
    May 2003
    Location
    Washington, USA
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why do you need to do this? Can't you just have a in table one, and then do a join when you need it with a select from table two?

  4. #4
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Home.
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Damn. Well that seems pretty obvious now ... Told you I was too dumb to see it. Damn my ***. I mean, it seems obvious in theory now.. but I'm still ignorant with the practical side of it..

    then add them to both tables with the same query.

    are the id's the same or what is linking those 2 tables together?
    Yeah, Field A needs to have the same properties/IDs/characters/stuff/whatever. What query would I need to use? o_O;

    Can't you just have a in table one, and then do a join when you need it with a select from table two?
    How would I go about doing this? Could you perhaps, maybe, possibly, I beg of you to, be so kind as to start me off with the query codes..? Maybe going in baby-steps? :\

    By the way, it's not just Field A by itself in those tables; there are other fields too. Just thought I'd let you now in case you were thinking that I wanted to basically duplicate two tables with the exact same details... o___O

    You are all the greatest of gentleman (and ladies, the greatest of ladies, if there so happens to be any registered here). Thank you ever so much. Me love you long time. I'll stop sucking up now.
    I AM NOT SENDING SUBLIMINAL MESSAGES.

    Stuff.

  5. #5
    SitePoint Guru
    Join Date
    Feb 2004
    Location
    Oregon
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it all depends on what is in the field A that makes them tied together. is it a ID form table one that will go into table two's field A? if so them it would look something like this
    PHP Code:
    $Q1 mysql_query("insert into table1 (id,fieldA) VALUES ('', 'whatever')");
    $lastId mysql_insert_id($Q1)
    $Q2 mysql_query("insert into table2 (id,fieldA) VALUES ('', '$lastid')");

    //
    // then to get the result of both tables it would be 
    //
    $Q1 mysql_query("select * from table1 
                              LEFT JOIN table2 NO (table2.fieldA = table1.fieldA) "
    ); 
    that is one way to do it. But like I said, it all depends on how you have it setup.
    success is not by chance, it is by choice.

  6. #6
    SitePoint Enthusiast rjahrman's Avatar
    Join Date
    May 2003
    Location
    Washington, USA
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    select tableA.fieldA, tableB.fieldB from tableA, tableB where tableA.id = tableB.id

    "Get fieldA from tableA, and then get fieldB from tableB where the rows have the same id (which is a primary key)."

    Look it up in the manual or a SQL tutorial.

  7. #7
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Home.
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, people. I'll try those out.

    I've messed about with both the queries a little.. but I'm not getting the desired result. Sorry if that sounds ungrateful, because I'm not. Thanks for your time and patience, I really appreciate it.

    it all depends on what is in the field A that makes them tied together. is it a ID form table one that will go into table two's field A?
    It's just normal text that links them together. Ideally, I wanted them linked through primary/foreign key relationships.

    Here's a last-ditch effort at trying to explain my needs.

    I have two tables with different fields in them.
    The primary key in Table1 is also a normal key in Table2.
    Would it be possible to be able to add records to Table One's primary key and then have the same records automatically appear in Table Two's foreign key?

    Sorry for the sucky explanations.

    I've researched a little on InnoDB tables. I have them all set up.. just stuck with queries and such.

    If someone has their own database that has the effect that I would like mines to have, I would really appreciate if you could send over e-mail or something.. just so I can have a solid look at the goings-on.

    Anyway, thanks again for the time people.
    I AM NOT SENDING SUBLIMINAL MESSAGES.

    Stuff.


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
  •