Writing to the top of a text file and paging issue help
Posted: Sat Apr 16, 2005 7:29 pm
Hi,
Is there a way to write to the top of a text file rather than to the bottom. I need to display my latest post at the top of the page. Currently it display this last.
Also i have a paging system in place which works, although it has a small downfall.
It creates page links but unfortuntely doesnt truncate them to 1 2 3....9 10 11 for example and rather display then as 1 2 3 4 5 6 and so on.
does anyone now a fix for this?
heres my code
thx
ari
Is there a way to write to the top of a text file rather than to the bottom. I need to display my latest post at the top of the page. Currently it display this last.
Also i have a paging system in place which works, although it has a small downfall.
It creates page links but unfortuntely doesnt truncate them to 1 2 3....9 10 11 for example and rather display then as 1 2 3 4 5 6 and so on.
does anyone now a fix for this?
heres my code
Code: Select all
<?php
include("header.inc");
$page = $_GET['page'];
if ($page == "") { $page = 1; }
$fwd = $page - 1;
$rwd = $page +1;
// Setting the default values for number of records per page -------------------------
$perpage = 100;
$filename = "data.php";
// Reading in all the records, putting each guestbook entry in one Array Element -----
$fd = fopen ("data.txt", "r");
while (!feof ($fd))
{
$buffer = fgets($fd, 4096);
$lines[] = $buffer;
}
fclose ($fd);
// Counting the total number of entries (lines) in the data text file ----------------
$result = count($lines);
$count = $result-1;
// Caclulate how many pages there are ----------------------------------------
if ($count == 0) { $totalpages = 0; }
else { $totalpages = intval(($count - 1) / $perpage) + 1; }
$end = ($page * $perpage) - 1;
$start = $end - ($perpage-1); if ($start <= 1) { $start = 0; }
if ($start < 0) { $start = 0; }
for ($i = $start; $i<=$end; $i++)
{
echo (stripslashes($lines[$i]));
}
echo "<center>";
// Creating the Forward and Backward links -------------------------------------
if ($fwd > 0 && $rwd > 0 && $rwd<$totalpages+1)
{
echo "<br><a href=\"$filename?page=$fwd\"><<</a>";
echo "<a href=\"$filename?page=$rwd\">>></a><br>";
}
else if ($fwd == 0)
{ echo "<a href=\"$filename?page=$rwd\">>></a><br>"; }
else if ($rwd == 0)
{ echo "<br><a href=\"$filename?page=$fwd\"><<</a>"; }
else if ($rwd == $totalpages+1)
{ echo "<a href=\"$filename?page=$fwd\"><<</a><br>"; }
for ($i = 1; $i<=$totalpages; $i++)
{
echo " [<a href=\"$filename?page=$i\">$i</a>] ";
}
echo "</center>";
?>
<?php
include("footer.inc");
?>thx
ari