Closed Thread Icon

Preserved Topic: limit number of display Pages that link to <a href="https://ozoneasylum.com/backlink?for=20869" title="Pages that link to Preserved Topic: limit number of display" rel="nofollow" >Preserved Topic: limit number of display\

 
Author Thread
cybergrafx
Paranoid (IV) Inmate

From: Earth
Insane since: Sep 2000

posted posted 03-16-2001 06:10

ok here is my scenario - I have a dir that has about 30 or so text files. I can already read out the contents of these files and display them on a page. But what I want to do is to be able to limit the display to like five at a time and then throw like a 'next' link at the bottom that displays the next five or so . . . does anyone have an idea how I can accomplish this?

thanx in advance . . .

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 03-16-2001 06:52

You didn't say in what programming language...

cybergrafx
Paranoid (IV) Inmate

From: Earth
Insane since: Sep 2000

posted posted 03-16-2001 17:13

I'm sorry, PHP.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 03-16-2001 19:10

Here's one way
First load all the variables into an array.

function GetDirArray($sPath)
{
//Load Directory Into Array
$handle=opendir($sPath);
while ($file = readdir($handle))
$retVal[count($retVal)] = $file;

//Clean up and sort
closedir($handle);
sort($retVal);
return $retVal;
}

Then using the array you can simply display 1 through 5. Pass the array along to the next page (or perhaps easier, itself) with a variable that tells it which number of items to display. I'll let you write the rest of the code simply because I'm lazy and really if you are just learning PHP it's a good basic lesson, but this I think is the trick to what you are trying to accomplish. If you hit a wall let us know.


Walking the Earth like Kane

cybergrafx
Paranoid (IV) Inmate

From: Earth
Insane since: Sep 2000

posted posted 03-16-2001 19:29

thanks bitdamaged but I think I need to clarify what I'm trying to do better. Ok I can go into the dir and display the dir listings 5 at a time, but where I'm stuck is to be able to then read out the contents of those 5 files. Like right now I'm using this:

--------------------------------------------------------------------------

function file_array($DIR){
$fd = popen("ls $DIR

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 03-16-2001 20:27

What I would do (there may be an easier way too) Is instead of using the implode, use a foreach loop (or "for" loop if you are not using PHP4)

foreach($parray as $var) {
print "$var <br>\n";
include( "$var");
print "<p>";
}




Walking the Earth like Kane

cybergrafx
Paranoid (IV) Inmate

From: Earth
Insane since: Sep 2000

posted posted 03-18-2001 04:48

yeah, but that's just another way of writing what I had already had, so that won't do what I'm looking for. I guess want I should be doing is grab $parray (since it contains the 5 file that I want at the moment) loop through that and then try to read the file contents out. I don't know if that would exactly do it . . .someone please correct me if I'm wrong.

thanx in advance . . . again.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 03-19-2001 05:36

No the include will print the files similar to an SSI call.
With include calls PHP drops out of parsing mode. and prints the contents of the files as HTML. The difference between this and SSI is that if you have PHP within the include file it will also be parsed BUT it must also be wrapped in its own delimiter tags.

Try the code you'll see it should work for you.


Walking the Earth like Kane

« BackwardsOnwards »

Show Forum Drop Down Menu