the following code is supposed to get the counts of records coming in and keep count of the records:
$count
$good_count
$bad_count
here is the code:
$count = count($data);
for ($i = 0; $i < $count; $i++)
{
//Process the records through business rules
$validate = validate_record($data[$i]);
//If an error is returned then write it out
$bad_count = 0;
if ($validate['ERROR'] != null)
{
//add headder to error output CSV file
if (!$error_headers_written)
{
$keys = array_keys($validate);
fputcsv($fp,$keys);
$error_headers_written = true;
}
fputcsv($fp,$validate);
$bad_count++;
}
}
//count check for DR reporting purposes
$good_count = $count - $bad_count;
$count works perfectly because it is just counting the number of records in a file
$bad_count is only supposed to increment if the $validate['error'] is not null
$good_count would work if I could get $bad_count to render the correct count
so can someone basically look at this part of the code:
$bad_count = 0;
if ($validate['ERROR'] != null)
{
//add headder to error output CSV file
if (!$error_headers_written)
{
$keys = array_keys($validate);
fputcsv($fp,$keys);
$error_headers_written = true;
}
fputcsv($fp,$validate);
$bad_count++;
}
and please tell me the dumb mistake that I am making