This topic is locked
[SOLVED]

 Adding records to Multiple Tables

8/23/2008 12:50:32 PM
PHPRunner General questions
J
jemmy239 author

Hello,
I have two tables. One is "Companies" and the other is "Owners".
Companies is setup as a master with primary key of "ID".

and

Owners is has a column for its own primary key and a forign key of "CompanyID".
So the company table lists various company information while th Owners table list all the owners for the companies.
Is there a way that when I add a new records for a company I can also add to the Owners at the same time?
I am new to SQL and PHP so thanks in advance!

A
alang 8/24/2008

The easiest way to do this in PHPR is to set up the Owners table as a detail table of Companies on the Datasource tables tab. When you display the list view of Companies, you will have an "Owners" (If you specify that as Caption) hyperlink against each company entry. After adding a new company, you would just click on this link to add the owners for that new company.

J
jemmy239 author 8/24/2008

Thanks! I think I do just that for now.
I am eventually trying to make just a one page application/form where you fill out the whole thing and it adds the owner fields to the owner tables.
Has anybody done anything like that with PHPR before?

J
Jane 8/25/2008

Hi,
PHPRunner doesn't support updating multiple tables on one page.

You can implement this manually using Before record updated/added events.
I.e. use something like this:

global $conn;

$sql = "update othertable set joinedfield=".$vales["joinedfield"]." ... ";

db_exec($sql,$conn);

unset($vales["joinedfield"]);

J
jemmy239 author 8/29/2008

Hi,

PHPRunner doesn't support updating multiple tables on one page.

You can implement this manually using Before record updated/added events.
I.e. use something like this:


Sorry as I am a newbie. I unserstand some of the code but not all of the logic.

Is there any documention that explain that code and which parts I would change and why?
Thanks

J
Jane 8/29/2008

Hi,
here is a sample SQL query:

select table1.id1,

table1.field1,

table1.field2,

table2.field3

from table1 inner join table2 on

table1.id1=table2.id2


You need to update table2 and then remove field3 from update SQL query for table1:

global $conn;

$sql = "update table2 set field3=".$vales["field3"]." where id2=".$values["id1"];

db_exec($sql,$conn);

unset($vales["field3"]);