This topic is locked
[SOLVED]

 Copy Record To Another Table

5/19/2013 12:48:55 PM
PHPRunner General questions
D
dustinforehand author

Hello All,

I am looking for a way to copy a record to another table.
I have two tables that are identical with the same fields, one is calendar and one is schedule.

Calendar (Table)

CalID, Case, Property, State, TimeStamp, Date
Schedule (Table)

ScheduleID, Case Property, State, TimeStamp, Date
The calendar is the main table I work with to schedule closings, but I want to giver external users access to add to the schedule. The external issue would have access to the schedule table to add a record. When I go in I would like to put a button on the edit page or the schedule table called confirm. Once I click confirm then that record would then copy to the Calendar table.
I tried this in mysql and I keep getting error that CalID is duplicate. I could not get this to work with the events with on the edit page after record update and I tried with the customer button.
Any help would greatly be appreciated.

C
cgphp 5/19/2013

Make sure CalID and ScheduleID are set as auto incement fields.

D
dustinforehand author 5/22/2013



Make sure CalID and ScheduleID are set as auto incement fields.


I did that, but he cal table is a lot bigger than the schedule table.. so the schedule table has id's that are already in the calid. is there away to copy the record over to the cal table and create a new id after it is copy.

A
Athlon 5/31/2013



I did that, but he cal table is a lot bigger than the schedule table.. so the schedule table has id's that are already in the calid. is there away to copy the record over to the cal table and create a new id after it is copy.


I would do it like something like this: events after record or before updated.
//** Save old/new data record in another table ****

global $dal;

$tblUsers = $dal->Table("YOURNEWTABLE");

$tblUsers->Param["ID"]=$values["ID"];//optional for where

$tblUsers->Value["Field1"]=$values["Field1"];

$tblUsers->Value["Field2"]=$values["Field2"];

$tblUsers->Value["Field3"]=$values["Field3"];

$tblUsers->Add();
return true;
// second table should be auto number and this field should not be included above.

Also useful for archive backup recovery....
Mike.