This topic is locked
[SOLVED]

 Trying to move record before delete

9/7/2019 7:55:19 AM
PHPRunner General questions
Tandy author

Hello All,

I have this code:



$rs = DB::Query("SELECT * FROM truck_notes_archive WHERE truck_note_id =".$deleted_values["truck_note_id"],"");

$data=$rs->fetchAssoc();

if($data)

{

$data = array();

$data["truck_note_id"] = $values["truck_note_id"];

DB::Delete("truck_notes", $data );}

else

{

$data = array();

$data["truck_note_id"] = $oldvalues["truck_note_id"];

$data["truck_id"] = $oldvalues["truck_id"];

$data["truck_number"] = $oldvalues["truck_number"];

$data["account_name"] = $oldvalues["account_name"];

$data["date"] = $oldvalues["date"];

$data["note"] = $oldvalues["note"];

$data["repaired"] = $oldvalues["repaired"];

DB::Insert("truck_notes_archive", $data );

}



In my List Page: Before Record deleted.

It is making a record in the Archives but no data if that makes sense. It just has the auto inc field in and the rest of the fields remain blank?

I have tried with different codes and none of them work in the List Page: Before Record Deleted.

I have no problem in the Edit or Add: Before Record Updated but it just does not seem to work where I need it the most.
Thanks All

James

lefty 9/7/2019



Hello All,

I have this code:



$rs = DB::Query("SELECT * FROM truck_notes_archive WHERE truck_note_id =".$deleted_values["truck_note_id"],"");

$data=$rs->fetchAssoc();

if($data)

{

$data = array();

$data["truck_note_id"] = $values["truck_note_id"];

DB::Delete("truck_notes", $data );}

else

{

$data = array();

$data["truck_note_id"] = $oldvalues["truck_note_id"];

$data["truck_id"] = $oldvalues["truck_id"];

$data["truck_number"] = $oldvalues["truck_number"];

$data["account_name"] = $oldvalues["account_name"];

$data["date"] = $oldvalues["date"];

$data["note"] = $oldvalues["note"];

$data["repaired"] = $oldvalues["repaired"];

DB::Insert("truck_notes_archive", $data );

}



In my List Page: Before Record deleted.

It is making a record in the Archives but no data if that makes sense. It just has the auto inc field in and the rest of the fields remain blank?

I have tried with different codes and none of them work in the List Page: Before Record Deleted.

I have no problem in the Edit or Add: Before Record Updated but it just does not seem to work where I need it the most.
Thanks All

James


If your trying to delete records in one table and archive to another table upon delete in the list page ,use $deleted_values not $oldvalues. That is why the auto ID is the only thing getting generated?

Reason being , once the record is added it is too late to grab the old value. So therefore we use $deleted_values on the list page to take a current record and do something with it. In your case it is Archive it , so

we use $deleted_values on the list page to archive in an event.

Tandy author 9/8/2019



If your trying to delete records in one table and archive to another table upon delete in the list page ,use $deleted_values not $oldvalues. That is why the auto ID is the only thing getting generated?

Reason being , once the record is added it is too late to grab the old value. So therefore we use $deleted_values on the list page to take a current record and do something with it. In your case it is Archive it , so

we use $deleted_values on the list page to archive in an event.



That worked out great.. Thanks John

I started with the built in code and ran it out from that. Wonder why the built in code is that way and not the right way? Oh well least now I know..
Thanks Again

James