<?php do {
........mySQL code here calling up a table row according to $pkcount.......
while(($file = readdir($dir)) !== false) {
if ($Player['pick'.$pkcount].'.jpg' == $file)
{$iconpic = $Player['pick'.$pkcount].'.jpg'; closedir($dir); break;}
else {$iconpic = "non.gif";}
}
............more code here, including img src=$iconpic.........
++$pkcount;
} while ($pkcount < 21); ?>
This works if my outter do/while statement only runs once. But if I set the do/while to anything higher the php just sits.
Is it valid to use a closedir and then loop around and "reddir" the same directory?
I have approx. 400 small icon files in a directory. I am trying to check if there is no icon match available it sets the current $iconpic = non.gif, right before an img src=$iconpic right outside of the "while"
I am looking for the most efficeint way to search each of 20 names in a database against 400 filenames in a directory. This could result in approx. 8000 file name reads. Is this partical? Or too hig?
My readdir in a while statment doesn't work.
Moderator: General Moderators
Simplified version of problem.
<?php
$pkcount = 1;
$dir = opendir("iconfaces");
do {
while(($file = readdir($dir)) !== false) {
echo $file;
}
++$pkcount;
} while ($pkcount < 3); ?>
Why won't this echo out all the file names more than once?
$pkcount = 1;
$dir = opendir("iconfaces");
do {
while(($file = readdir($dir)) !== false) {
echo $file;
}
++$pkcount;
} while ($pkcount < 3); ?>
Why won't this echo out all the file names more than once?
it should but only once
take a look at http://www.php.net/manual/en/function.rewinddir.php
and it might be faster to store the filenames in an array the first time the script iterates the directory (depending on the amount of files that may cost some memory)
take a look at http://www.php.net/manual/en/function.rewinddir.php
and it might be faster to store the filenames in an array the first time the script iterates the directory (depending on the amount of files that may cost some memory)