thomasw_lrd Posted June 22, 2012 Share Posted June 22, 2012 I'm writing a script that will email our compliance officer if all the files have been uploaded for a case, but if the files are not uploaded, it will email the case manager to let them know that the files don't exist and they need to get them. The problem I am having is that I do not want to have 7 variables for each file. I want one variable, and when it's false, send an email. If it comes back true 7 times, then email compliance. I've considered using an array, but I'm not sure how to check if all the values are true. I've considered using switch or do-while loops to handle it. Any thoughts or suggestions are much appreciated. Here is what I have so far, and of course the if statements won't handle it, because if the last file is there, then the variable will be set to true. I also can't exit out of the $files_names while loop, because we will have multiple cases that need to be checked. //This while loop will loop through all files for all that cases that were selected in while($files_names=mysql_fetch_array($files)) { //Find files with SAA in the filename if (preg_match("/SAA/i", $files_names['name'])){ $funding_book = True; } else { $funding_book = False; }//end the SAA if statement //Find files with CSP Seller in the filename if (preg_match("/CSP Seller/i", $files_names['name'])){ //echo "CSP Seller: "; echo $files_names['name']; echo "<br>"; $funding_book = True; //echo "New Value: "; echo $funding_book; echo "<br>"; } else { $funding_book = False; }//end the CSP Seller if statement //Find files with STA POA in the filename if (preg_match("/STA POA/i", $files_names['name'])){ echo "STA POA Seller: "; echo $files_names['name']; echo "<br>"; $funding_book = True; echo "New Value: "; echo $funding_book; echo "<br>"; } else { $funding_book = False; } //end the STA POA if statement } //end the files_names while loop } //end row while loop Quote Link to comment Share on other sites More sharing options...
Barand Posted June 22, 2012 Share Posted June 22, 2012 nm Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 22, 2012 Share Posted June 22, 2012 OK, before I get to your issue, if you have a condition that will only set a variable to true or false you do not need to create an if/else condition. Just do something like this $funding_book = (preg_match("/SAA/i", $files_names['name'])) I would assume you would want to provide some details to the case manager as to which files have not been uploaded. But to just check that all files are there or not just set a flag variable at the beginning to true, then as you check for each file you only need to check if it is NOT there - if so set the flag to false. <?php $allFiles = true; //This while loop will loop through all files for all that cases that were selected in while($files_names=mysql_fetch_array($files)) { //Find files with SAA in the filename if (!preg_match("/SAA/i", $files_names['name'])){ $allFiles = false; } //Find files with CSP Seller in the filename if (!preg_match("/CSP Seller/i", $files_names['name'])){ $allFiles = false; } // . . . etc. . . . ?> Then at the end you only need to check that the variable is true. but, I would do something to keep track of which files have and have not been uploaded so you can provide that info in the email. Quote Link to comment Share on other sites More sharing options...
thomasw_lrd Posted June 22, 2012 Author Share Posted June 22, 2012 That is what I was looking for. Thank you. I also didn't how to handle not true preg_matches. It's the ! in the front. Again, thanks so much. And you are correct, I want to email the case manager which files are not there. I was going to set up an array to handle that. I seem to have misplaced the solved button again? Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 22, 2012 Share Posted June 22, 2012 OK, in retrospect I see that won't work. Each iteration of that loop is only processing one file. Give me a sec and I'll post a different solution. I think it will require multiple variables - but we can simplify it. Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 22, 2012 Share Posted June 22, 2012 OK, I don't see any solution but to use seven different variables because each iteration of the while() loop is a new event and you need to have a history of the events previously. But, it can be simplified. Here is some mock code <?php $file1 = false; $file2 = false; $file3 = false; // . . . //Loop through each fiel and set appropriate var to true if matching file found while($files_names=mysql_fetch_array($files)) { //Find files with SAA in the filename if (preg_match("/SAA/i", $files_names['name'])){ $file1 = true; } //Find files with CSP Seller in the filename if (preg_match("/CSP Seller/i", $files_names['name'])){ $file2 = true; } //Find files with STA POA in the filename if (preg_match("/STA POA/i", $files_names['name'])){ $file3 = true; } //Etc. . . . for each file you are looking for } //end the files_names while loop //One condition check for all files if($file1 && $file2 && $file3) { //All files are present } else { //All files are NOT present } ?> Quote Link to comment Share on other sites More sharing options...
thomasw_lrd Posted June 22, 2012 Author Share Posted June 22, 2012 I think this will work, since then I have a while loop, and an inner while loop to handle the files. I'm gonna test it Monday morning. I forgot to post the outer while loop in my original question. Logic is a while loop to loop through all cases, an inner loop to loop through all files for a particular case. So we will loop through, if a file does not exist, then we set $funding_book = False, so as long as we get one false, it should email the case manager, if we get no falses, then $funding_book = True, and we will email the compliance officer. That makes logical sense to me, but I may be wrong. //another while loop to select cases. $funding_book = True; //This is an inner while loop will loop through all files for all that cases that were selected in outer while loop while($files_names=mysql_fetch_array($files)) { //Find files with SAA in the filename if (!preg_match("/SAA/i", $files_names['name'])){ $funding_book = False; }//end the SAA if statement //Find files with CSP Seller in the filename if !(preg_match("/CSP Seller/i", $files_names['name'])){ $funding_book = False } //end the CSP Seller if statement if ($funding_book = False) { //email case manager; } else { //email compliance officer } } //end the files_names while loop } //end row while loop [\code] 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.