This topic is locked

Importing field data from master table...

12/2/2009 12:32:30 PM
PHPRunner General questions
C
CodeDog author

Quick question about using data from another table to populate a field.
If I have a master/child relation, and I add a record to the child table, what would be the best way to use data from a field in the master table record to populate a field in the child record I'm adding?
mastertable->field > childtable->field
I'll be using the data to relate the child records back to the master record.
I'm thinking it would be an event that I would add after the child record had been added, and I would likely be using DAL, but I'd like to know the best way to do it. I'm just getting my feet wet with PHPRunner and want to do this the right way.
I'm using PHPRunner 5.1 Build 2503.
Thanks for any help...

J
Jane 12/3/2009

Hi,
use Add page: Before process event to select values from master table and save it in the session variables.

Here is a sample:

global $dal,$strTableName;

if ($_SESSION[$strTableName."_masterkey1"])

{

$rstmp = $dal->TableName->Query("FieldName=".$_SESSION[$strTableName."_masterkey1"],"");

$datatmp = db_fetch_array($rstmp);

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

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

}



Then use $_SESSION["Field1"] and $_SESSION["Field2"] as default values on the "Edit as" settings dialog on the Visual Editor tab.

C
CodeDog author 12/3/2009

Thanks so much, Jane, that was exactly what I needed. Now that I've finally got time to start working with PHPRunner I'm really liking the flow. Simple, but a lot of ability to do whatever you want. Already looking forward to 5.2...