I am trying to implement pagination for my news script ran on flat text files, and i can't get the 'core' idea to work - to display particular items from an array (For example display all items from 10 to 20, from 0 to 10, from 1000 to 2000 - you get the idea). This is where i got one more mysql advantage - you can use a very handy LIMIT clause there. So how do i "emulate" it with arrays? It's got to be very simple, but i suck at programming. I tried array_slice($array, 10, 10) ; array_slice($array, 10, 20) and same for array_splice. Can anybody help me?
here the current code i have if it helps...
$max_results = 10;
$from = (($page * $max_results) - $max_results);
$to = $from + $max_results;
echo $from;
echo $to;
if ( $handle = opendir("news/") )
{
while ( ( $file = readdir( $handle ) ) !== false )
{
if ( $file != "." && $file != ".." )
{
$news_array[] = $file;
}
}
closedir( $handle );
}
array_multisort( $news_array, SORT_NUMERIC, SORT_DESC );
$news_total = ( count($news_array ) );
array_slice($news_array, 10, 20); <------ Need Help Here
$num_news = ( count( $news_array ) );
foreach ( $news_array as $val )
{
output hereeee
}
Other unrelated stuff here(such as the actual page numbers output)
Would be great if anybody would help a neewb
Thanks