This topic is locked

Insert Field in Master Table From Child

10/13/2009 11:42:52 AM
PHPRunner General questions
D
dilbertbert author

This is probably already covered somewhere within the forum but for the life of me I cannot find it by searching.
Here is my question:
I have a table called "LdItem" (Master Table) and a table called "LdTest"
The LdItem table contains items that must be inspected at different intervals in our facility. The LdTest table contains the results of those tests.

In the LdTest table there is a field called NextTest, this is a date field. There is also a field in the LdItem field called NTestDate. Every time a record is added or edited in the LdItem table I want it to insert the NextTest field value into the master table, LdItem, in the NTestDate field.
Can anyone help me with the custome code event?
Thanks!!!

J
Jane 10/14/2009

Hi,
use After record added/After record updated events on the Events tab for this purpose.

Here is a sample:

global $dal,$strTableName;

$dal->LdItem->NTestDate = $values["NextTest"];

$dal->LdItem->MasterKey = $_SESSION[$strTableName."_masterkey1"];

$dal->LdItem->Update();



where MasterKey is your actual field name.

D
dilbertbert author 10/14/2009

Jane,
Thank you for your reply! I'm really struggling with this.
I tried putting in the snippet of code you gave me on the events, I'm afraid coding is not my strong point.
I keep getting an error from the following line: $dal->LdItem->NTestDate = $values["NextTest"];
The error is: Undefined variable: values
I'm sure I'm doing something wrong, any ideas?
Thanks!

J
Jane 10/15/2009

Please give me more detailed description of what you're doing.

What PHPRunner version do you use? Where do you add your code?

D
dilbertbert author 10/15/2009



Please give me more detailed description of what you're doing.

What PHPRunner version do you use? Where do you add your code?


I'm on version 4.0 and I'm inserting the code in events - Add Page - After Record Added
When the child recorded added (table name: LDTest) I want the field (NextDate) inserted into the master record (table name: LDItem) into the field (NTestDate).
You must get tired of helping people with coding, I very much appreciate your help.

J
Jane 10/16/2009

Hi,
move your code to the Before record added event for PHPRunner 4.0.

D
dilbertbert author 10/16/2009

Thanks!
It went a little further, now I'm getting the following error:
Fatal error: Call to undefined method stdClass::Update() in C:\xampp\htdocs\lab\include\ldtest_events.php on line 16

J
Jane 10/19/2009

Hi,
here is the correct code:

global $conn,$strTableName;

$strUpdate = "update LdItem set NTestDate='".$values["NextTest"]."' where MasterKey=".$_SESSION[$strTableName."_masterkey1"];

db_exec($strUpdate,$conn);



where MasterKey is your actual field name.

D
dilbertbert author 10/19/2009

That code worked PERFECTLY!
Thank you so very much!