Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
mysql LIMIT function in simple Arrays
Old 05-16-2005, 02:19 PM mysql LIMIT function in simple Arrays
Average Talker

Posts: 20
Trades: 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...
PHP Code:
$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_arraySORT_NUMERICSORT_DESC );
$news_total = ( count($news_array ) );
array_slice($news_array1020);  <------ 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
tima89 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-16-2005, 02:37 PM
OmuCuSucu's Avatar
Vi Veri Veniversum Vivus

Posts: 1,168
Name: Dragos-Valentin
Location: Cluj-Napoca, RO
Trades: 0
can you not use a for() ? let's say display 10 at a time:

PHP Code:
for ($i 0$i $news_total$i++) {
   while (
fmod($i10) !== 0) {
      echo 
$news_array[$i];
   }
   
next_page_link.

haven't tested it but it should work.
while the newsnumber/10 has a rest echoes the stuff...

you can replace 10 with whatever you want to use.
i'm sure there's a much easier solution ....
__________________
.
» Please remember to add to my Talkupation if you enjoyed my post. Thank you :)
.
OmuCuSucu is offline
Reply With Quote
View Public Profile
 
Old 05-18-2005, 08:50 AM
Average Talker

Posts: 20
Trades: 0
This is a really hard resolution, isn't there a function that is supposed to do something like that? I think i will just move to mysql
tima89 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to mysql LIMIT function in simple Arrays
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.70921 seconds with 12 queries