This topic is locked
[SOLVED]

 Set data for old records

2/26/2020 8:39:42 AM
PHPRunner General questions
E
Eddy Keuninckx author

I have a table with a lot of data in it.
Recently, new fields were added to this table and now these fields are empty for the old records. This is not an issue as long as the old records are not modified.
However, the new fields are mandatory, so when the old records are modified, the new fields should get the requested data.
To minimize the workload and to avoid errors, I would like to automate this.
For the new added records, the fields are (mostly) filled in by the "Autofill" function(s) of a dropdown box(es). Should I put sql-code somewhere in "Before Display" or what is the best way?
Cheers

N
Nir Frumer 2/26/2020

hi

in such cases I opt for "not changing the code"

so I just fill the table with 0 for id's, out of date dates for dates, '*' for characters etc..
doing some update ... where "New_field" is null (this may change a bit depending on the database you use)
hope it helps,

Nir.

E
Eddy Keuninckx author 2/26/2020



hi

in such cases I opt for "not changing the code"

so I just fill the table with 0 for id's, out of date dates for dates, '*' for characters etc..
doing some update ... where "New_field" is null (this may change a bit depending on the database you use)
hope it helps,

Nir.


Thanks Nir for your advice.
Cheers

lefty 2/26/2020



Thanks Nir for your advice.
Cheers


If you just leave it like it is , when an old record is empty , it should just modify the new field upon edit. It may be necessary to change the each field to "use different settings for all pages" and have a default value for the auto update field. If you don't want to modify any old records that have no data then you need to add code to edit event before record updated to set the old record field to empty or Null ( depending on what it was ).
Something like this for strings . depends on empty or null see below?
If ($oldvalues["yourfield"]=="") {

$values["yourfield"] = "";

}

else {

// continue updating fields with new data

}
Just make sure database field is not set to not null. See differences between empty and Null HERE.

E
Eddy Keuninckx author 2/27/2020

Thanks John, very useful advise.