et4891 Posted February 25, 2013 Share Posted February 25, 2013 can't believe I'm here again...here three days straight. ok hummm...ok I created a loop to check if the contents are correct or not if the contents does not preg_match what I need then it'll print out an error message with a link to an error.log file... anyways somehow if all the contents are valid/matches what's in preg_match then I'm printing out all the contents in a table. I'm not considering anything about the table at this moment but when it outputs my last row of contents two times *there are only three rows of contents at the moment* else //else file exist then.......else #1 { $fileContents = file("./courses/" . $_GET["filename"]); //calls out the file into $fileContents[] array....so $fileContents[0] is like the first row of the contents $datePrinted = false; //setting a flag first so the date will be print only once when there's error..being used later in the foreach loop $error_message = false; //setting a flag so error message only show once and being used later in the foreach loop $well_formed = false; //another flag unlooping the message saying the file is correctly formed $table = false; $error_check = 0; sort($fileContents); foreach($fileContents as $row) //the contents will be then seen as $row { $column = preg_split("/,/", $row); //splits the row by , and name each array as $column $error_log = fopen("./courses/path/error.log","a+") or die ("File can not be opened"); //creates/open an error.log file if(!(isEmailAddressWellFormed($column[3])) || !(isStudentNumberWellFormed($column[0]))) //two functions calls from page4.php using preg_match to check email and student# validation //if one of them do not validate the following will start { $error_check++; if(!$error_message) //if this is false then the error message+link will show { echo "Errors have been found in " . $_GET['filename'] . "<br/><a href='./courses/path/error.log'>Click here for the log</a>"; $error_message = true; //since this is in a loop but doesn't need to print it out so many times so changing the value here to true so when this loop runs again if(!error_message) will not run again } if(!$datePrinted) //works as how error_message works. the date only print once by here { fwrite($error_log, date("F t, Y (h:i:s a)") . PHP_EOL); $datePrinted = true; } if(!(isEmailAddressWellFormed($column[3]))) //checks again if the email is not valid then print the follow to error.log { fwrite($error_log, "Improper email address from" . $_GET["filename"] . " :" . PHP_EOL); fwrite($error_log, "$column[2] $column[1] $column[3]" . PHP_EOL); } if(!(isStudentNumberWellFormed($column[0]))) //checks again if the student # is not valid then print the follow to error.log { fwrite($error_log, "Improper student numbers from" . $_GET["filename"] . " :" . PHP_EOL); fwrite($error_log, "$column[2] $column[1] $column[0]" . PHP_EOL . "\n"); } } elseif($error_check == 0) { $row.=$row; } }//closing foreach fwrite($error_log, str_repeat("-",80) . PHP_EOL); //puts a line to separate the next error but each time the page runs this line will print even if there's no error fclose($error_log); if($error_check == 0) { echo "<h1 style='color: red'>" . $_GET["filename"] . " is well formed.</h1>"; echo "<table>"; echo $row; echo "</table>"; } }//closing else #1 I think it's somewhere here that I messed up elseif($error_check == 0) { $row.=$row; } but no idea how I should correct it.... Quote Link to comment https://forums.phpfreaks.com/topic/274907-loop-is-not-showing-everything-i-want/ 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.