This topic is locked

Same Data, two tables

10/19/2005 1:46:43 PM
PHPRunner General questions
O
omegix author

Hi,
My main table has various fields, including "username" and "email."
I have a second table that is linked to the first via username.

There is also a field for e-mail in my second table.
Is there a way to automatically copy the information in the Main-Table's email field to the Second-Table's email field?
Example:

Main table: Username, birthday, favoritecolor, table1_email

Second Table: Username, event, rsvp_status, table2_email
Upon creaton of entry into second table, username and e-mail of currently

logged in user are placed in their respective fields.
Thanks,

Jeff

admin 10/20/2005

Jeff,
you can do the followig:
1. Select Second Table in PHPRunner and open Formatting tab. Enter

@$_SESSION["email"]



as a default value for table2_email field.
2. Ensure that you checked off Display Master table info box on Datasource table tab in PHPRunner.

Build the pages.
3. Open generated second_list.php file with a text editor, locate the following snippet:

if($rsMaster)

{

$data=db_fetch_array($rsMaster);



and insert the following just after it

$_SESSION["email"]=$data["table1_email"];



where table1_email is the exact field name on your first table.

OCTheEagle 10/26/2005

Hi,
I've got the exact same situation here. I however can't find the snippet you described in step 3.
I've got 2 tables. In the first table called 'noord' there are 4 fields: ID, Naam, Zaak afdeling. In the second table called 'email'
there are 3 fields: ID, Naam, mail.
You can find both list.php files here

admin 10/26/2005

This sample code applies to Master-Details case only with Dsiplay Master table info option turned on.

OCTheEagle 10/28/2005

Ah I see, thanks.

I kinda mis-translated your previous answer. Sorry for that. English is not my first language. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=6562&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

500353 11/10/2005

Is there also a way to have the info sent the other way?
Let´s say the main tabel is the master and the second table is the detail table.
When the user changes the field in ´table2_email´ that the field ´table1_email´ automatically adapts thesame value.

admin 11/10/2005

Hi, you can insert the followng line into generated detail_edit.php file:

db_exec("update mastertable set table1_email=".$evalues["`table2_email`"]." where id=".$_SESSION[$strTableName."_masterkey"],$conn);



where mastertable and id are your actual master table name and its primary key.
Insert it just after this snippet:

LogInfo($strSQL);

db_exec($strSQL,$conn);

OCTheEagle 11/10/2005

Thanks for your answer.
Unfortunately I get an 'Undefined variable: evalue' error when I want to edit a row in the master table and press the 'submit' button. Also, when I edit the value in the table2_email field then the value in table1_email field doesn't change.

admin 11/10/2005

I'm sorry. I corrected my previous post.
You should modify Edit page for detail table, not master.

OCTheEagle 11/14/2005

Hi,
Editing a row in the master table works now, when I edit a row in the detail table I still get an 'Undefined variable: evalue' error.
Could it perhaps be because the field in the master en detail table have thesame name? Does the field in the detail table need to have a default session value?

admin 11/14/2005

Hi,
please correct your code as I did in py previous post.

The correct variable name is evalues, not evalue.