-1

Below is my code for the question mentioned in the title:

                $folder = '/net/comp/home/data/';
                $files1 = scandir($folder);
                $analysisno=($row['ANALYSIS_NUMBER']); //e.g.11wa666
                //if ($test = strstr($folder,'$analysisno'))
                if (in_array($analysisno,$files1))              
                {       
                //echo " --$test completed, match found";
                echo "  <td BGCOLOR=\"#00ff00\">completed</td>\n";              
                }
                else
                {
                echo "  <td BGCOLOR=\"#00ffff\">pending</td>\n";

The if statement does not seem to work correctly, as when testing: there is a file in the directory above which contains an analysis number which the if statement should check and output completed. ( this is the problem).

( All I would like to do is check if a file with the analysis number in its filename is present in the directory specified then output 'completed' if there is no existance of the analysis number in the folder then output queued).

By default the code always outputs 'pending' and does not output completed when necessary.

Thanks for any help.

genesis
  • 50,477
  • 20
  • 96
  • 125
donok
  • 135
  • 2
  • 11
  • 1
    Have you tried debugging your code? Printing the various values of your variables? – Alex Turpin Oct 24 '11 at 14:17
  • hi I have done that, sorry forgot to mention, for instance analysis number does have values in there e.g. 11r3666 and all the other values from the database its fetching it from. – donok Oct 24 '11 at 14:21
  • 1
    var_dump your variables to see the types, and also, does it have any file extension? – Mob Oct 24 '11 at 14:21
  • @damien pirsy, thanks for all replies, I am actually checking for a match in the filename, could you explain or possibly suggest another way please. – donok Oct 24 '11 at 14:24
  • @Mob hi I just done the var dump and the correct elements seem to be in array, yes they do have file extensions. – donok Oct 24 '11 at 14:29
  • 1
    @donok maybe you should add the extensions to the analysis number e.g 11wa666 – Mob Oct 24 '11 at 14:32
  • @mob thanks I think I may have a try on this, although it will be difficult as there is two more random characters added to the end of the analysis number and then the .pdf – donok Oct 24 '11 at 14:35
  • @donok there are better ways to do this than using array unique, btw – Mob Oct 24 '11 at 14:53
  • @Mob please could you suggest another way, even something to google that may help. Thanks for your prompt replies. – donok Oct 24 '11 at 15:10

1 Answers1

2

print the $files1 array after the $files1 = scandir($folder); and see what the array contains

after that print the $analysisno value and check if the value actually in the array.

your code seems good

Eli Y
  • 877
  • 16
  • 41
zion ben yacov
  • 715
  • 6
  • 13