Welcome to WebmasterWorld Guest from 3.214.184.124

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

mysql LIMIT function in simple Arrays

     
8:54 pm on May 18, 2005 (gmt 0)

New User

10+ Year Member

joined:Apr 8, 2005
posts:8
votes: 0


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 tems 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 sucks 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
11:22 am on May 20, 2005 (gmt 0)

New User

10+ Year Member

joined:Apr 8, 2005
posts:8
votes: 0


So does anybody know how to do it?
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members