This topic is locked

How copy data from one table to another table

2/11/2018 5:13:24 AM
PHPRunner General questions
P
pell.net author

I have a question.

How to copy data from one table to another table. In the data display I would set the button for each record and when the user clicks the button all the data in that line is copied to another table. For example When some job done the data should be copied to the backup table.

thank you

jadachDevClub member 2/11/2018

Here is how I would do that in C# (sorry, I am an ASPRunner.Net guy). It will be easy enough to translate though. Just look at the help file.
Make a copy of your table that will hold the newly copied data.
On the list page add a button.
Client Before empty
Server

result["record"] = button.getCurrentRecord();

{

dynamic tblMyOtherTable = GlobalVars.dal.Table("dbo.MyOtherTable");

tblMyOtherTable.Value["ID"] = keys["ID"].ToString();

tblMyOtherTable.Value["Field1"] = result["record"]["Field1"].ToString();

tblMyOtherTable.Value["Field2"] = result["record"]["Field2"].ToString();

tblMyOtherTable.Value["Field3"] = result["record"]["Field3"].ToString();

tblMyOtherTable.Add();

// you may also want to update the original record telling the user it has been copied.

}


Client After

location.reload(); // or something else
romaldus 2/11/2018
  1. Empty the "client before" event
  2. In server event



global $dal;
$record = $button->getCurrentRecord();
//if productID is not empty

if ($record["ProductID"])
{

$sql="INSERT INTO another_table (ProductID, ProductName, ProductCategory) values ('".$record["ProductID"]."',

'".$record["ProductName"]."',

'".$record["ProductCategory"]."')";
CustomQuery($sql);

}
$result["txt"] = "Product was copied";


3. In client after:
location.reload();

P
pell.net author 2/16/2018

global $dal;
$record = $button->getCurrentRecord();
//if productID is not empty

if ($record["idIspita"])
{

$sql="INSERT INTO another_table (Oib, Prezime, Ime, Spol, ImePrezimeOca, ImePrezimeMajke, DatumRodenja, MjestoRodenja, DrzavaRodenja, Drzavljanstvo, AdresaStanovanja, GradStanovanja, NazivPrograma, DatumUpisaPrograma, TemeljUpisaPrograma, NazivPrograma, DatumPolaganjaIspita, DatumIzdavanjaIsprave, Idgrupe, VoditeljObrazovanja) values

('".$record["idIspita"]."',

'".$record["Oib"]."',

'".$record["Prezime"]."')",

'".$record["Ime"]."',

'".$record["Spol"]."',

'".$record["ImePrezimeOca"]."',

'".$record["ImePrezimeMajke"]."',

'".$record["DatumRodenja"]."',

'".$record["MjestoRodenja"]."',

'".$record["DrzavaRodenja"]."',

'".$record["Drzavljanstvo"]."',

'".$record["AdresaStanovanja"]."',

'".$record["GradStanovanja"]."',

'".$record["NazivPrograma"]."',

'".$record["DatumUpisaPrograma"]."',

'".$record["TemeljUpisaPrograma"]."',

'".$record["NazivPrograma"]."',

'".$record["DatumPolaganjaIspita"]."',

'".$record["IdGrupe"]."',

'".$record["VoditeljObrazovanja"]."')";
CustomQuery($sql);

}
$result["txt"] = "Zapis je kopiran u MaticnuKnjigu";
And the result is server error.
Did the problem occur because the data above has been taken from multiple query tables?

Or is it become of something else?