This topic is locked
[SOLVED]

Migrate data from a medium field to a table

7/5/2024 1:48:00 AM
PHPRunner General questions
J
Jan author

Hello everyone, I have a table with the following fields:
ID and text (= mediumtext field)
The content of the text field consists of a few numbers, coming from a hand scanner. (See photo). I want to migrate each number into a separate record of another table. How can I fix this?

img alt

C
Chris Whitehead 7/5/2024

You'll need to explode/split the field value in "after record added" then loop round the elements.

// split the field value, any of these should work to make the field an array, I've provided a few just in case of sod's law.
$numbers = preg_split('/\r\n|[\r\n]/', $values['nummer']);
$numbers = explode("\r\n", $values['nummer']);
$numbers = explode(PHP_EOL, $values['nummer']);

// then just loop through the elements
foreach( $numbers as $number ) {
// save the record in the table using DB::Insert
}
J
Jan author 7/5/2024

Works great. Thanks.

C
Chris Whitehead 7/6/2024

No prob, glad it worked. I had the same issue a while back with IP address in a text area and needed to save them individually for access.