SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: foreign key

  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    foreign key

    $qryp2="INSERT INTO `cleopark`.`t_reservation` (
    `id` ,
    `today` ,
    `entrance` ,
    `adult` ,
    `kids` ,
    `infant` ,
    `tot` ,
    `g_tot` ,
    `pers_id`
    )VALUES (
    NULL,
    CURDATE(),
    '$date',
    '$adult',
    '$children',
    '$infant',
    '$total',
    '$grand_tot',
    here i want to get the id of the second table to use it
    )";


    $qryp1="INSERT INTO `cleopark`.`personal` (
    `id` ,
    `name` ,
    `address` ,
    `telephone` ,
    `emal` ,
    `city` ,
    `country` ,
    `t_res_id`
    )VALUES (
    NULL, '$family',
    '$address',
    '$tele',
    '$emalb',
    '$cityb',
    '$country',
    here i want to get the id of the first table to use it
    )";

    all i need is to get the id of the first table and display it in the second table in slect * query
    and also
    i need to display the second id in the first table

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Why do you need to cross-reference like that? One of those two foreign keys should be enough.
    Like this, it's a bit like the story about the chicken and the egg

  3. #3
    SitePoint Zealot smadeira's Avatar
    Join Date
    Oct 2003
    Location
    Pennsylvania
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't see the point of having two tables if you are doing a 1 for 1 linking between rows in the tables. If this is the design then why don't you just make it one table. You are going to have redundant data regardless.

    A better way to do it would be to take the personal information, check to see if it is already in the database (from a previous transaction) and use that ID in your reservation table.

    If a reservation can have more than one 'personal' data row then you would need an intersection table between the two tables to handle the many-to-many relationship.
    Scott


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
  •