This topic is locked

Adding records from another table

9/20/2013 10:54:20 AM
PHPRunner General questions
B
bencroftweb author

Hi
I want to copy the data from our main client table to say a quotation table so I can stamp all their current details into the quote. Meaning they could amend their address and create another quote but the original quote has all the previous data stored.
I can get the ID to carry over through the Table Link Properties but not everything else because if they change any of the details in the main client table it loses the relationship to the records.
so I want to copy from the client table to the Quotation table for example:
Title -> Title

FullName -> Fullname
and so on.
I am thinking that I should link the 2 tables and then use the "before display" option in Events to prefill.
Is this a good way/efficient?
Thanks
Ben

C
cgphp 9/20/2013

Not sure I understand your table layout. You could link the two tables in the following way:

MAIN TABLE

==========

id

field_1

field_2

field_3
QUOTE TABLE

===========

id

main_table_id

last_quote


You can fetch the last quote and additional data for a customer, selecting the max id from the QUOTE table where the main_table_id is equal to the id of the MAIN table.
Hope to be clear.

B
bencroftweb author 9/20/2013

Interesting I didn't know how to pull the last entry as a template. But not what I'm after right now.
I have a clients table - Name, Address, Postcode, etc.
I want to create a quote and copy pretty much all of the clients details into the quote table so if in future the client changes the address details that the original address details of the quote are maintained.
I hope that makes sense - it's does to me but then again I can miss the point entirely when typing :-)
Thanks again
Ben

C
cgphp 9/20/2013

What are the fields the clients could change in the future? And could you list the fields of your table?

B
bencroftweb author 9/20/2013



What are the fields the clients could change in the future? And could you list the fields of your table?


Client Table
FullName

Address1

Address2

Address3

CityTown

Postcode

Tel

Mob
Quote Table
FullName

Address1

Address2

Address3

CityTown

Postcode

Tel

Mob

Product1

Product2

Product3

Product4

Product5
If I use "Table Link Properties" and the client moves address so I update the client fields then it loses the child link because the details no longer match and then hides the previous quotes so I wanted a way to stamp all the details in but only using the ID to link the 2 tables.

C
cgphp 9/20/2013
CLIENT TABLE

============

id

FullName
ADDRESS TABLE

=============

id

client_id (this field is likend with the id field of the Client table)

Address1

Address2

Address3

CityTown

Postcode

Tel

Mob
QUOTE Table

===========

id

address_id (this field is likend with the id field of the Address table)

Product1

Product2

Product3

Product4

Product5
B
bencroftweb author 9/21/2013


CLIENT TABLE

============

id

FullName
ADDRESS TABLE

=============

id

client_id (this field is likend with the id field of the Client table)

Address1

Address2

Address3

CityTown

Postcode

Tel

Mob
QUOTE Table

===========

id

address_id (this field is likend with the id field of the Address table)

Product1

Product2

Product3

Product4

Product5



I have changed the table structure to how you have suggested as it makes perfect sense, however I still need to copy/stamp certain key details over from the address into the quotation table.
How do I copy data from a field in the master table to child table when I click "Add New" without using "Table link properties"?
Thanks again
Ben