msimonds Posted March 13, 2008 Share Posted March 13, 2008 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 Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 13, 2008 Share Posted March 13, 2008 $bad_count will never go above 1. You define it as 0 within your loop... therefor every time the loop executes, it resets to 0. try moving it outside the loop, or put static in front of the declaration static $bad_count = 0 if (.... Quote Link to comment Share on other sites More sharing options...
msimonds Posted March 13, 2008 Author Share Posted March 13, 2008 yeah I saw that, thanks so much Matt! never mind stupid mistake on my part fixed Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.