Using the INSERT command to another table in AfterSave()
Archived from the Xataface Users forum.
neotrode — Fri Jan 13, 2012 7:25 am
Hello,
I have two tables. Table1 contains some standard text fields and a text field for place holding the name of the file upload (field name: NL_photo). Table2 is a table associated with Table1 for additional photos using the relationships.ini in Table1. All works well. However, I have a particular request like this…
When a user enters a new row in Table1, the file upload field (NL_photo) is also inserted to Table2 as well (T2_photos). To do this, I was going to write some form of “INSERT” query to Table2 in Table1’s Delagate class in function AfterSave. However, I do not know the list of commands I can use to call an INSERT command to another table. Can you lead me to the online documentation explaining this? Basically I need access to the DB commands I can use in the table’s Delagate class functions.
Thanks.
Best,
Frank
Jean — Mon Jan 16, 2012 5:58 am
Hello Franck,
Go to the delegate_class in the table1 directory and add a after_insert($record) :
- Code: Select all
- `function after_insert($record){
$this->app =& Dataface_Application::getInstance();
$id_table1=$record->val(‘id_table1’);
$sql = “INSERT INTO table2…WHERE…”;$res = mysql_query($sql, $this->app->db());
}`
Cheers
Jean