Reputation: 1105
I developed a program - a data matcher of two CSV file. Sample input of the data in CSV file is below.
user_transaction:
user name | email | amount | blank | total | n/a | ok | bank name | date
bank_transaction:
date | transact details | n/a | location | blank | for status | amount
So what my program do is looking for all bank transaction(date and amount) match to users data.
Here is my code doing it.. jdoodle.com/a/3Ev
Any idea?
When clicking done of a specific row should add data to the status row from the bank_transaction CSV file.
My purpose here is to mark done
all that I have check/confirm bank transaction detail.
Upvotes: 0
Views: 638
Reputation: 1889
When I click done of a specific row, How can I add data to the status row
For the form (where your button "Done") just set the row number (or file position from ftell
; then fseek
to focus on), it'll simplify the update.
Also do not use customized parsers for CSV. Try fgetcsv
// Open file, cursor at the beginning
$stream = fopen('bank_transaction.csv', 'r+', false);
// Take focus position
$idx = filter_input(INPUT_POST, 'ftell', 0, FILTER_VALIDATE_INT);
if ($idx) {
fseek($stream, $idx);
// $maxLineLength - define it earlier
$data = fgetcsv($stream, $maxLineLength, ',', '"');
... update required field ...
// Set position back after read
fseek($stream, $idx);
fputcsv($stream, $data, ',', '"');
}
Upvotes: 1