Comparing a text file to a DB
Posted: Tue Jul 16, 2002 11:08 am
I was wondering if this is possible: Compare a row from a table to a row from a text file, and if that row is not in that text file, then delete it from that table, and move it to another one. Say for example I read in a text file and assign the following variables:
Then I have a table Active with the same fields:
LastName, FirstName, MiddleName, SSN
And an Inactive table exactly the same
LastName, FirstName, MiddleName, SSN
This text file is inserted into the Active table.
The reason is, is that this text file is updated every 2 weeks, and only current data should be maintained, with an archive for old data. So again, I want to move data from the Active table to the Inactive table which is not present in the text file. Can anyone give me an idea on how to do this??? Hope all this makes sense, if not let me know and ill try to clarify it more. Thanks
Code: Select all
$fd = fopen ("d:\active.txt", "r");
while (!feof ($fd)) {
$line= fgets($fd, 4096);
$MyArray=explode("|", $line);
$LastName=addslashes($MyArrayї0]);
$FirstName=addslashes($MyArrayї1]);
$MiddleName=$MyArrayї2];
$SSN=$MyArrayї3];Then I have a table Active with the same fields:
LastName, FirstName, MiddleName, SSN
And an Inactive table exactly the same
LastName, FirstName, MiddleName, SSN
This text file is inserted into the Active table.
The reason is, is that this text file is updated every 2 weeks, and only current data should be maintained, with an archive for old data. So again, I want to move data from the Active table to the Inactive table which is not present in the text file. Can anyone give me an idea on how to do this??? Hope all this makes sense, if not let me know and ill try to clarify it more. Thanks