Skip to main content
Topic: UpdateRecord in page event with table_data's value from other table (Read 1242 times) previous topic - next topic

UpdateRecord in page event with table_data's value from other table

Here is my tables:
user -> user_id, username, password, email, name, address_u
data -> data_id, user_id_d, address_d, data_1, data_2

and then i use this UpdateRecord Page Event statement in AfterAdd in 'data' table:
Code: [Select]
$table_data = array(
    "user_id_d" => "value",
    "address_d" => "value2"
);
$db->where("data_id", $rec_id);
$bool = $db->update("data", $table_data);

what code above does is when i add a record to 'data' table, the current record will have "user_id_d" and "address_d" autofilled with "value" and "value2".
my question is, is there anyway to replace "value" and "value2" with dynamic value from other table?
for example what i want to do here is:
Quote
"user_id_d" => get user_id from user
"address_d" => get address_u from user
something like that. is there anyway to achieve it?


 

Re: UpdateRecord in page event with table_data's value from other table

Reply #2
thank you @willvin for your assistance xD

here is the solution:
Code: [Select]
$modeldata['user_id_d'] = get_active_user('user_id');
$modeldata['address_d'] = get_active_user('address_u');
do it in beforeAdd instead of afterAdd