Okay, I have a tab delimited file and I need to read through that file and compare each line to the data in a database table. If there is a match, I need to set a flag in the database table to 'active' and update the address and phone number. If there is no match, I need to add that whole record to the table and set the flag to 'active'.
I've written the code create the tab delimitted file which is here...
// Query the SEAS_FTP database and then write the results to a tab delimited file
$sqlSelect="SELECT student_number
, first_name
, last_name
, DOB
, street
, city
, state
, zip
, home_phone
, gender
, grade_level
FROM seas_ftp
WHERE school_id='2917'"; //add our conditions to the where clause
$conn = db_connect_s_services();
$resultSelect = mysql_query($sqlSelect,$conn);
$fileWriteName="security.txt";
// Writes the query results to the file. Overwrites existing data.
$fileput = fopen($fileWriteName, "w+");
while($list = mysql_fetch_row($resultSelect)) {
fputcsv($fileput, $list);
}
function fputcsv($handle, $row, $fd="\t", $quot='"')
{
$str='';
foreach ($row as $cell) {
$cell=str_replace(Array($quot, "\n"),
Array($quot.$quot, ''),
$cell);
if (strchr($cell, $fd)!==FALSE || strchr($cell, $quot)!==FALSE) {
$str.=$quot.$cell.$quot.$fd;
} else {
$str.=$cell.$fd;
}
}
fputs($handle, substr($str, 0, -1)."\n");
return strlen($str);
}
I understand how to read through the file and insert all the results into the DB but not how to read the file and do the comparisons.
Any help is much appreciated. Also, if more information or code is needed, let me know.
Thanks in advance.