This topic is locked
[SOLVED]

fieldname list in AfterUpdate Event

9/1/2022 7:43:01 AM
PHPRunner General questions
K
kohle author

Hi ,

after a record is updated i need to write a log with changes of field values.
I have access with oldvalues and values of the content, but i need the fieldnames too.

In javascript client before/after for buttons I have access with : rowData
for(var fName in rowData.fields){

Is there something similar for php in the AfterUpdate event.

rgs
J.

W
wpl 9/1/2022

Hi J.,

maybe you could give "array_keys($values)" a try.

Regards

fhumanes 9/1/2022

Hello,

Check this example. $values and $oldvalues, are associative arrays. https://flexiple.com/php/php-foreach/

In the example you will find this code, which is the one you need.

<?php
$freelancer = array(
"name" => "Eric",
"email" => "Eric@gmail.com",
"age" => 22,
"gender" => "male"
);

// Loop through employee array
foreach($freelancer as $key => $value) {
echo $key . ": " . $value . "
";
}
?>

Cheers,
fernando

K
kohle author 9/2/2022

Hi,

I am back here late, because I didnt receive an email about the posts.

Thanks for the answers but its not what I am looking for.

Maybe I explain it different :
I want to write a function which I can use in the AfterUpdate event for different tables.

One way is :

$fieldnames = array("name", "email", "age" ,"gender" );
foreach ($fieldnames as $field) {
if($values($field)!=$oldvalues($field)
{
//execute sql for insert into log table
}
}

The problem is I need to know the fieldnames and have to put them into an array,
but for writing a global function this is not helpful.

I am looking for something like to receive the names :

$fieldnames = rowData.fields ; (retrieving the fieldnames in the Afterupdate event)

// and than I process them

foreach ($fieldnames as $field) {
if($values($field)!=$oldvalues($field)
{
//execute sql for insert into log table
}
}