CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 COPY TABLE DATA

Print topic Send  topic

Author Message
softmafia

Posts: 44
Posted: 08/08/2009, 7:30 AM

I wan to be able to copy data from a particular table to another with one record form

For Example i have two tables ( TablesA and TableB)

TABLE A

id
name
surname
age

TABLE B
id
name
surname
age

There Is a Record form that is used to input data into Table A i want to be able to use update to copy the same data to TABLE B when i click to update
please can anyone Help me with this or the Custom Code thanks

_________________
softmafia
View profile  Send private message
ckroon

Posts: 869
Posted: 08/08/2009, 10:48 PM

http://www.databasejournal.com/features/mssql/article.p...-to-Another.htm

Gonna have to do some Custom SQL commands on an After Insert/Update event.

_________________
Walter Kempees...you are dearly missed.
View profile  Send private message
mentecky

Posts: 321
Posted: 08/09/2009, 10:11 AM

softmafia,

In your record After Update event you'd need something like:
  
$db = new clsInternet(); // change for your DB class  
$SQL = "INSERT INTO tableB (name, surname, age) FROM SELECT name, surname, age FROM tablea WHERE id=".CCGetParam("id","");  
$db->query($SQL);

Hope that helps!

Rick

_________________
http://www.ccselite.com
View profile  Send private message
ckroon

Posts: 869
Posted: 08/09/2009, 10:12 PM

Get rid of the first FROM :)

_________________
Walter Kempees...you are dearly missed.
View profile  Send private message
mentecky

Posts: 321
Posted: 08/09/2009, 10:35 PM

Thanks CK... I hate when my fingers do stuff before my mind thinks about it.

Rick
_________________
http://www.ccselite.com
View profile  Send private message
GrzegorzL

Posts: 13
Posted: 08/21/2009, 5:46 AM

Perfect
Many thanks
View profile  Send private message
TonyReid


Posts: 159
Posted: 08/22/2009, 2:30 PM

I'd usually use the SELECT INTO statement when copying into other tables.

Not sure if there is much performance benefit doing it that way as opposed to above, but I think it might be a little faster.
_________________
-----------
PHP/indy Game Developer - http://www.AbsoluteBreeze.co.uk
View profile  Send private message
mentecky

Posts: 321
Posted: 08/22/2009, 2:44 PM

TonyReid,

I believe after the server optimizes the query they end up being pretty much the same. I prefer INSERT INTO simply because it's easy to read when debugging. Just a personal preference.

You may well be right if were talking a large dataset though.

Rick
_________________
http://www.ccselite.com
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.