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 Link to comment https://forums.phpfreaks.com/topic/96038-trying-to-get-correct-counts/ 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 (.... Link to comment https://forums.phpfreaks.com/topic/96038-trying-to-get-correct-counts/#findComment-491671 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 Link to comment https://forums.phpfreaks.com/topic/96038-trying-to-get-correct-counts/#findComment-491677 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.