This topic is locked

Moving a record to another table with a choice..?

11/13/2008 7:18:56 PM
PHPRunner General questions
S
stugutz author

Hi ya

Question...

I have 5 tables with 10 identical fields in all the tables.

I want to move a record to another table but I wish to choose the table to enter it into. And then delete it from the original table if at all possible.
Is this possible?

If so how do I go about it, I have searched the forum and found some answers but they don't really help me as they mainly related to 1 table.
Perhaps at a later version this could be implemented as a feature. (Either move or copy to another table)
regards vjc

J
Jane 11/14/2008

Hi,
you can do the following:

  1. edit SQL query on the Edit SQL query tab. Here is a sample:
    select Field1,

    Field1 as TableCopy,

    ...

    from TableName


2. check off TableCopy on the copy page only on the Choose fields tab.
3. check value of this field in the Before record added/updated events on the Events tab and save record in the correct table.

Here is a sample:

$strUpdate = "insert into ".$values["TableCopy"]." ...";

db_exec($strUpdate);
unset($values["TableCopy"]);

S
stugutz author 11/14/2008

Thx Jane

Unfortunately my php is quite vague, still getting the jift of it...
Can you please make a little more understanding for me..?
Lets say my tables are called ....table 1, table 2, table 3.....etc all the way to table 5.

Lets say my fields are called ....field a, field b, field c, field d....etc all the way to field 10.
How would I write this based on the question I ask at the topic start?
Once again many thanks, the product and suppport of the product is 1st class!

J
Jane 11/17/2008

Hi,
you can publish your project on Demo Account and send to support@xlinesoft.com a URL to your pages along with detailed description of what you want to achieve and I'll try to help you.

S
stugutz author 11/26/2008

Hi

I guess publishing it to the demo account wont really solve the coding.
All I need to know is what to use as the code
Lets say my tables are called ....table 1, table 2, table 3.....etc all the way to table 5.

Lets say my fields are called ....field a, field b, field c, field d....etc all the way to field 10.
How would I write it so I can move a record to another table and delete it from the original table?
Lets say I made a mistake in adding info and I saved it but found out it went to the wrong table. Instead of deleting that record all I want to do is move it to the right table...
eg:

table 1 has 5 fields and I want to move all the fileds to another table....say table 2. (or table 3, or table 4 etc... my choice) ...remembering that all my tables has identical named fields.
I'm sure that this code to be used would be a handy one for many people...??
many thanks

PS: I'm not trying to be rude by the way <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=35482&image=1&table=forumreplies' class='bbc_emoticon' alt=':P' />

J
Jane 11/26/2008

Hi,
you can do the following:

  1. edit SQL query on the Edit SQL querytab. Here is a sample:
    select fielda,

    fielda as TableCopy,

    ...

    from TableName


2. check off TableCopy on the copy page only on the Choose fields tab.
3. check value of this field in the Before record added/updated events on the Events tab and save record in the correct table.

Here is a sample:

global $conn,$strTableName;

//save record in another table

if ($values["TableCopy"])

{

$strUpdate = "insert into ".$values["TableCopy"]." (fielda, fieldb) values (".$values["fielda"].", ".$values["fieldb"].")";

db_exec($strUpdate,$conn);

}

unset($values["TableCopy"]);
//delete from current table

$strDelete = "delete from ".$strTableName." where RecordID=".$_REQUEST["editid1"];

db_exec($strDelete,$conn);
return false; //redirect to the list page

header("Location: table1_list.php");

exit();