PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
jgmcelwain
Forum Newbie
Posts: 4 Joined: Thu Aug 12, 2010 11:12 am
Post
by jgmcelwain » Thu Aug 12, 2010 11:14 am
Anyone got any ideas why this would display the first of $files, then the tenth, then the second, thrid and fourth etc. instead of the first, second, third, fourth fifth etc.?
Code: Select all
<?php function xfunction($page = 1, $num_posts = 5) {
$start = (($page - 1) * $num_posts);
$path = "content/posts/";
$files = glob("" . $path . "*.txt");
if ($files) {
rsort($files);
$files = array_slice($files, $start, $num_posts);
foreach ($files as $file) {
print("\n<article>");
include($file);
print("</article>\n");
}
} else {
echo "Somthing's Missing? Maybe you need to <a href='install.php'>Install?</a>";
}
} ?>
jgmcelwain
Forum Newbie
Posts: 4 Joined: Thu Aug 12, 2010 11:12 am
Post
by jgmcelwain » Thu Aug 12, 2010 11:42 am
Files are named 1.txt, 2.txt, 3.txt etc.
mikosiko
Forum Regular
Posts: 757 Joined: Wed Jan 13, 2010 7:22 pm
Post
by mikosiko » Thu Aug 12, 2010 11:48 am
simple test.... what happens if you have a file named 20.txt ... in which position it will came?
again... did you tried the GLOB_NOSORT ?
jgmcelwain
Forum Newbie
Posts: 4 Joined: Thu Aug 12, 2010 11:12 am
Post
by jgmcelwain » Thu Aug 12, 2010 12:33 pm
20.txt comes after 2.txt. GLOB_NOSORT didn't do anything. :S
mikosiko
Forum Regular
Posts: 757 Joined: Wed Jan 13, 2010 7:22 pm
Post
by mikosiko » Thu Aug 12, 2010 12:48 pm
jgmcelwain wrote: 20.txt comes after 2.txt.
Ok... now you have something to start investigating... why that happens?
I'm not going to solve it for you... I'm just giving you clues about the reasons for your issue.... time to google
happy learning
jgmcelwain
Forum Newbie
Posts: 4 Joined: Thu Aug 12, 2010 11:12 am
Post
by jgmcelwain » Thu Aug 12, 2010 12:57 pm
Ok, thanks for pointing me in the right direction.