Hi,
I did a tutorial on posting news to a text file and then accessing the data...
Everything worked fine, until I wanted to put in a limit on how many posts to view on a page and add next previous links...
Can someone help?
Here is the code:
<?php
// if a page isn't defined, we're on page one
if($page <= 0)
{
$page = 1;
}
$data = file("news.txt");
$data = array_reverse($data);
// how many lines of data to display
$display = 5;
// where to start depending on what page we're viewing
$start = ($page * $display) - $display;
// the actual news we're going to print
$news = array_slice($data, $start, $display);
// printing the data
foreach($news as $key=>$value)
{
foreach($data as $element) {
$element = trim($element);
$pieces = explode("|", $element);
echo $pieces[2] . "<BR>" . "<b>Posted by " . $pieces[1] . " on " . $pieces[0] . "</b><BR><BR>";
print("line $key: $value<br>\n");
}
}
?>