PDA

View Full Version : Include Newest


dudeking
January 23rd, 2007, 07:12 PM
I have been trying to edit a script buzz helped me with a while back so I can just include the file that is listed first alphabetically in a directory.

<?php
$dh = opendir("stories/");
$count='0';
while ($entry = readdir($dh)) {
if ((strpos($entry,'.php') !== false) && ($entry!=='index.php')) {
if ($count >= '1' ) {
include('stories/'.$entry);
}
$count++;
}
}
closedir($dh);
?>

Well to cut it short, it doesn't work lol

Buzz
January 24th, 2007, 03:48 AM
Change

if ($count >= '1' )


That reads "if greater than or equal to 1"

you want "if is equal to 1", so use this instead:

if ($count == '1' )


but since you just want 1 entry you may not need the while loop. I'd need to research more. I don't do a whole lot of articles from files systems databases are so much easier.