DanielHardy Posted July 29, 2009 Share Posted July 29, 2009 Hi, I have the following guestbook code up and running perfectly. However, the guestbook area currently occupies a small area on an already full page. I was hoping for guidance on how I would go about displaying the first say 5 results, and then offerring a link to a page that would display all of the results. Any sort of help is appreciated. <?php // Save filename to variable. $guestbook = "messages.txt"; // This will run if someone sends user input. if (isset($_POST['button'])) { // Check whether any fields are empty or not. if (!empty($_POST['name']) && !empty($_POST['message'])) { // Bad characters in E-Mail string. $badSearch = array("@", "."); // Goods characters in E-Mail string. $goodSearch = array(" @ ", " . "); // Grab name from the form and add a newline afterwards. $string .= "<b>" . $_POST['name'] . " "; // Grab email and replace the @ and . in the string. $string .= str_replace($badSearch, $goodSearch, $_POST['email']) . "</b>\n"; // Grab the message and save it in $string. $string .= "<font color=#2766c5>" . $_POST['message'] . "</font>\n<hr>"; // Open messages.txt and append more posts to it. $file = fopen($guestbook, "a"); // Write $string to the text file and replace bad characters to avoid XSS attacks. fwrite($file, nl2br(strip_tags($string, "<b><hr><font>"))); // Close the file we opened. fclose($file); echo '<script>alert("Your comment has been added ")</script>'; } else { // Of the form fields are empty will there popup a message. echo '<script>alert("Please fill out the whole form")</script>'; } } // This will read the file and print out everything in the text file. // Open and read the messages.txt file. $readfile = fopen($guestbook, "r"); // Read and print out everything in the page. echo @fread($readfile, filesize($guestbook)); // Close the file we opened. fclose($readfile); ?> Thanks Dan Link to comment https://forums.phpfreaks.com/topic/167904-link-to-results-rather-than-automatically-display/ Share on other sites More sharing options...
lonewolf217 Posted July 29, 2009 Share Posted July 29, 2009 http://www.w3schools.com/PHP/php_file.asp look into using a for or while loop with fgets and a simple counter. once you hit the 5 records you want, display a link and close the file Link to comment https://forums.phpfreaks.com/topic/167904-link-to-results-rather-than-automatically-display/#findComment-885590 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.