This topic is locked

getting data from master table in adding process

2/22/2008 2:19:33 PM
PHPRunner General questions
A
adrian trujillo author

Is there a direct way to get the field values from master table (not the masterkeys) when I am adding a detail record ... and use them to fill some other fields in the detail record before to display add window ? .
I would appreciate, any help.
<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=7653&image=1&table=forumtopics' class='bbc_emoticon' alt=':)' />

A
amuro 2/25/2008

If the field is recorded in SESSION, you are able to get its value directly.

Otherwise, get the field value via masterkey. I think so <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=26322&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />

Alexey admin 2/26/2008

Hi,
sure, you can.

You need to select a record from the master table and save selected values in session variables.

Then use session variables as Default values in details table.

I.e. set the following Default values for your detail fields:

$_SESSION["Field1"]

$_SESSION["Field2"]

...
And here is the sample code for Add page:Before page processed event:

global $conn,$strTableName;

$sql = "select * from mastertable where id=".$_SESSION[$strTableName."_masterkey1"];

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

$data = db_fetch_array($rs);

$_SESSION["Field1"] = $data["Field1"];

$_SESSION["Field2"] = $data["Field2"];

...