2 questions:
1, How do i go about reversing the output from a textfile, im already using Fopen to read a flat file line by line, then using explode to separate the data peices
2, how do i paginate the above?
2 questions:
1, How do i go about reversing the output from a textfile, im already using Fopen to read a flat file line by line, then using explode to separate the data peices
2, how do i paginate the above?
use file() to read the whole file contents as an array,
once you have the lines in an array, with a simple for cycle
you can make it visible.
pager?
once you have the whole file in an array, you can get its values with a for cycle. And make links with start and block positions.
[man]strrev()[/man], reverses strings.
paginate what?
rincewind456;10929022 wrote:1. [man]strrev()[/man], reverses strings.
- paginate what?
1, Not litteraly reverse it letter by letter, reverse the order they are displayed first entries last, and last entries first.
2, paginate the comments, obviously i don't want 2-300 comments on one page.
why don't you store these comments in database?
NOT tested but something like this:
<?php
/*
READ ALL THE COMMENTS INTO AN ARRAY CALLED $items
AND DO A COUNT ON THE ARRAY AND CALL IT $count
*/
#Set number of images per page
$items_per_page = 10;
#Calculate number of pages for links
$pages = floor($count/$items_per_page);
$last_page = $count % $items_per_page;
#Construct page links
$page_links = ''; #Initialize variable
for ($i=0;$i <=$pages;$i++){
$page_links .= '<a href="page.php?p='.($i+1).'">'.($i+1).'</a>'."\n"; #Change page.php to your required page name
}
#Check to see if page chosen
if(isset($_GET['p'])){
$page_number = (int) $_GET['p'];
}
#set default page number to display the first batch of images
else
{
$page_number =1;
}
#Calculate which images to display
$diff = $page_number*$items_per_page;
$first_item = $diff-($items_per_page-1);
$last_item = $diff;
$display_items ='';
if ($last_item> $count) {
$last_item = $count-1;
}
for ($i =$last_item;$i <= $first_item-1;$i--){
$display_items .= '<p>'.$item[$i]."<p>\n<br />";
}
print $display_items; # Display the image code
print '<div style="text-align:center;">'.$page_links.'</div>'; #Display the page links code
?>
Because the idea is that it is a Flat File Guestbook, its much easier to set up than a database for those who aren't as savy when it comes to using PHP.
I may consider a MYSQL Version as a later release
one suggestion to the posted code, you should use htmlspecialchars on the printed comments to protect your program from user injected scripts.
djjjozsi;10929029 wrote:one suggestion to the posted code, you should use htmlspecialchars on the printed comments to protect your program from user injected scripts.
I shall include htmlspecialchars in the 1.1 update which I am working on for the 1st October.
Any other suggestion on security etc would be greatly appreciated.
homer09001 wrote:Because the idea is that it is a Flat File Guestbook, its much easier to set up than a database for those who aren't as savy when it comes to using PHP.
I may consider a MYSQL Version as a later release
Then you may want to consider [man]SQLite[/man] if you want flat file storage.