This topic is locked

Redirect Master/Detail Woes!

9/3/2008 10:13:50 AM
PHPRunner General questions
N
nix386 author

Hi there, just wondering if someone can point me in the direction as I have nearly lost all hope of resolving this myself. I think I have searched nearly every post regarding master detail redirection and yet this still eludes me.
I currently have a master table and detail table linked by 'id', everything is working fine with adding to the detail table from the master table.

This is an example of the table structure..
master table

id (auto inc)

name

code (unique value)
detail table

tid (auto inc)

name

code (unique value)

id
I want to be able to do both of the following.

  1. When the detail link is clicked I want to skip the detail list page and go directly to the detail add page ( this I already have working ) but if a record already exists for this master/detail relationship based on the unique "code" field then don't display the add page but instead go directly to the view page of that existing record.
  2. If a record already exists for this master/detail relationship based on the unique "code" field then I would skip the detail list going directly to the detail add page then as the new record is added redirect back to the view page for this new detail record.
    So to put it simply as I can; if a record with same "code" field exists then redirect to view that record, if record with same "code" field does not exist then add the new record and redirect to view of this new record, gaaaarhhh my head is spinning... <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=9414&image=1&table=forumtopics' class='bbc_emoticon' alt=':blink:' />
    Any help would be greatly appreciated.
    Cheers, Nick

L
laurent 9/3/2008

Hi Nick,
Remark:
To put it simply you want to create a (1:0) Master-Detail relationship:

1 record Master table correspond 0 or 1 Detail record.

1 record Detail Table must have 1 record Master Table
Have a look at:

Cardinality in Database Relationships
Cheers,

N
nix386 author 9/3/2008

Hi Nick,

Remark:
To put it simply you want to create a (1:0) Master-Detail relationship:

1 record Master table correspond 0 or 1 Detail record.

1 record Detail Table must have 1 record Master Table
Have a look at:

Cardinality in Database Relationships
Cheers,


Thanks for the reply Laurent, I am looking at this now.. unfortunately I know just enough to be a nuisance ..

J
Jane 9/4/2008

Nick,
useList page: Before processevent for detail table on the Events tab for this purpose.

Check number of records on the detail list page and redirect to the corresponding page.

Here is a sample code:

global $conn;

if (@$_REQUEST["masterkey1"])

{

$str = "select * from `detail table` where code=".$_REQUEST["masterkey1"];

$rs = db_query($str,$conn);

if ($data = db_fetch_array($rs))

{

//record exist

header("detail_table_view.php?editid1=".$data["tid"]);

exit();

}

else

{

//there is no record for selected master record

header("detail_table_add.php?mastertable=master_table&masterkey1=".$_REQUEST["masterkey1"]);

exit();

}

}

N
nix386 author 9/4/2008

Jane, I think I love you! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=32704&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' />

global $conn;

if (@$_REQUEST["masterkey1"])

{

$str = "select * from `detail table` where id=".$_REQUEST["masterkey1"];

$rs = db_query($str,$conn);

if ($data = db_fetch_array($rs))

{

//record exist

header("Location: detail_table_view.php?editid1=".$data["tid"]);

exit();

}

else

{

//there is no record for selected master record

header("Location: detail_table_add.php?mastertable=master_table&masterkey1=".$_REQUEST["masterkey1"]);

exit();

}

}