This topic is locked

move record

12/12/2008 5:47:32 AM
PHPRunner General questions
M
mauro author

It's possible move a record from a table to another table in the same database?

J
Jane 12/12/2008

Hi,
where do you want to move this record? Are field name the same in both tables?

Please post more detailed description of what you want to achieve.

M
mauro author 12/12/2008

Hi,

where do you want to move this record? Are field name the same in both tables?

Please post more detailed description of what you want to achieve.


I have:
Database

------> table A (field name: name, tel, id)

------> table B (field name: name, tel, id)
fileds in Table A and B are the same i need to move periodically same records from table A to B

J
Jane 12/12/2008

Hi,
here are some tips:

  1. proceed to the Visual Editortab
  2. turn on HTML mode, find this line:
    {BEGIN delete_link}



and add following code just before:

<A onclick="frmAdmin.a.value='move'; frmAdmin.submit(); return false;" href="#">Move</A>


And add some code to theBeforeDeleteevent:

//delete records

if(@$_POST["a"]=="delete")

return true;
global $conn;

if(@$_POST["a"]=="move")

{

$strMove = "insert into TableB (name, tel, id) values ('".$deleted_values["name"]."',".$deleted_values["tel"].",".$deleted_values["id"].")";

db_exec($strMove,$conn);

}

S
stugutz 5/25/2009

Hi

based on your example ....what if I wanted to move the record and select which table to send it to.
Example:

Database

------> table A (field name: name, tel, id)

------> table B (field name: name, tel, id)

------> table C (field name: name, tel, id)

------> table D (field name: name, tel, id)
I want to be able to move the record to my choice of table.
Example:

I want to move a record from Table A and insert it to my choice of either Table B, C, or D then delete it from Table A
thanks

J
Jane 5/26/2009

Hi,
you can create three links: for TableB, TableC and TableD and process it in the BeforeDelete event separately:

if(@$_POST["a"]=="moveB")

{

$strMove = "insert into TableB (name, tel, id) values ('".$deleted_values["name"]."',".$deleted_values["tel"].",".$deleted_values["id"].")";

db_exec($strMove,$conn);

$strDelete = "delete from TableA where id=".$deleted_values["id"];

db_exec($strDelete,$conn);

}

if(@$_POST["a"]=="moveC")

{

$strMove = "insert into TableC (name, tel, id) values ('".$deleted_values["name"]."',".$deleted_values["tel"].",".$deleted_values["id"].")";

db_exec($strMove,$conn);

$strDelete = "delete from TableA where id=".$deleted_values["id"];

db_exec($strDelete,$conn);

}