Jump to content

.txt file pagination from a folder/directory


moise

Recommended Posts

hi, i was using test files to display some of my website contents[code]<div id="content">

<p>
<?php
$filename="mypagecontent.txt";
$fp=fopen ($filename, "r") or die ("Couldn't open $filename");
while (! feof ($fp))
{
$line = fgets ($fp, 1024);
print "$line<br>";
}
?>
</p>

</div>[/code],
however, i have a page were i would like to display several contents (7) at the same place with pagination. all files are in a folder and i would please like some help to sort this out. any help is welcome...
many thanks.
[code]<?php
txtArray = ("file1.txt", "file2.txt", "file3.txt", "file4.txt", "file5.txt", "file6.txt", "file7.txt");

$thisPage = (isset($_GET[page])) ? $_GET[page] : txtArray[0];

echo "<div class=\"pagination\">";

$pageNum = 0;
foreach (txtArray as $fileName) {
    $pageNum++;
    if ($fileName==$thisPage) {
        echo "&nbsp;&nbsp;" . $pageNum . "&nbsp;&nbsp;"
    }
    else {
        echo "&nbsp;&nbsp;<a href=\"urlToThisPage?page=" .$pageNum . "\">" . $pageNum . "</a>&nbsp;&nbsp;"
    }
}
echo "</div>";

echo "<br>\n";

echo "<div id=\"content\"><p>\n";

$fp=fopen ($thisPage, "r") or die ("Couldn't open $thisPage");
while (! feof ($fp))
{
$line = fgets ($fp, 1024);
print "$line<br>";
}
echo "</p></div>\n";

?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.