Jump to content

Pagination - how to


DanielHardy

Recommended Posts

Please view my following code. How would I go about adding pagination to my results with 5 results shown and then next and previous links. Iknow i need a counter and a while loop but I am still unsure about how to achieve this.

 

<?php
  
   $guestbook = "messages.txt";

  
   if (isset($_POST['button']))
   {
  
      if (!empty($_POST['name'])  && !empty($_POST['message']))
      {
  
         $badSearch = array("@", ".");
  
         $goodSearch = array(" @ ", " . ");
  
         $string .= "<b>" . $_POST['name'] . "  ";
           $string .= str_replace($badSearch, $goodSearch, $_POST['email']) . "</b>\n";
  
         $string .= "<font color=#2766c5>" . $_POST['message'] . "</font>\n<hr>";
         
  
         $file = fopen($guestbook, "a");
           fwrite($file, nl2br(strip_tags($string, "<b><hr><font>")));
  
         fclose($file);
         echo '<script>alert("Your comment has been added ")</script>';
      } else {
  
         echo '<script>alert("Please fill out the whole form")</script>';
      }
   }
   
  
  
   $readfile = fopen($guestbook, "r");
  
   echo @fread($readfile, filesize($guestbook));
  
   fclose($readfile);

?>

 

Any help is greatly appreciated

 

Thanks

 

Dan

Link to comment
https://forums.phpfreaks.com/topic/167988-pagination-how-to/
Share on other sites

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.