This topic is locked

update fields after import finished

1/23/2016 7:56:54 PM
PHPRunner General questions
L
laonian author

My table has following fields:
ID (INT, primary, auto_increment)

system_serial (varchar)

other fields ...
The system_serial field is generated by the system as follows after record is added:
global $conn;

$serial_id='MYSYS-'.$keys["ID"];

$updatesysid="update mytable set system_serial='".$serial_id."' where ID=".$keys["ID"]."";

db_exec($updatesysid, $conn);
This is working fine.
Now I want to import data for this table, and both ID and system_serial fields are empty from the import table. The ID field is entered by the system. But I don't know how to update the system_serial field in after import finished event. I simply don't know how to access the field value arrays in this event.
Could some one help? Thank you.

Sergey Kornilov admin 1/24/2016

You need to use BeforeInsert event for this purpose:

http://xlinesoft.com/phprunner/docs/before_insert_record.htm
In AfterImportFinished event you do not have access to anything you can use for this task.

L
laonian author 1/24/2016

Thanks Admin for the reply.
I tried this in the Before insert record of import page event:
$values['system_serial']='MYSYS-'.$values["ID"];
but $values["ID"] was NULL.
Any idea on how to get the value of this key field of newly inserted record?

Sergey Kornilov admin 1/25/2016

Yes, this is a BeforeInsert event, record is not added yet and autonumber key is not generated. We do not have an event that would happen after single record was imported. AfterImportFinished is executed once after all records were imported. I guess you need to rethink your import logic.