Jump to content

GrizRule

New Members
  • Posts

    7
  • Joined

  • Last visited

GrizRule's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have my website paginating files that are shown onscreen. How can I make it so the page only loads the first page's files and then when going on to the next page, it loads the files on that page? Basically what I am trying to do is reduce load time by not loading the files on the pages after page one until the user actually goes to a page after page one. index.php <?php $current_page = isset($_GET['page']) ? intval($_GET['page']) : 1; $items_per_page = 10; $offset = ($current_page - 1) * $items_per_page; $items = glob("entries/*.php"); $total_items = count($items); $total_pages = ceil($total_items / $items_per_page); foreach (array_slice($items, $offset, $items_per_page) as $entry) { include $entry; } echo "<table summary=\"\" cellpadding=\"10\" cellspacing=\"0\" border=\"0\" class=\"global-links-menu\"><tr>"; if($current_page != 1) { $back_page = $current_page - 1; echo "<td ><p><a href='?page=$back_page'>Back</a></p></td>"; } else { $back_page = $current_page - 1; echo "<td ><p></p></td>"; } for($j=1;$j<=$total_pages;$j++) { if($j==$current_page) { echo "<td ><p>$current_page</p></td>"; } else { echo "<td ><p><a href='?page=$j' title='Page $j'>$j</a></p></td>"; } } if($current_page <= $total_pages - 1){ $next_page=$current_page+1; echo "<td ><p><a href='?page=$next_page'>Next Page</a></p></td>"; } else { echo "<td ><p></p></td>"; } /* foreach (glob("entries/*.php") as $filename) { include $filename; } */ ?> </table>
  2. I do not want that PHP code inside $new_message to be executed inside the script above, I want it to be executed in the new file that it made when the script above is ran. That is why I put the opening php tag inside the echo. I want it inside the new file
  3. <?php error_reporting(E_ALL); ini_set('display_errors', 1); session_start(); //Starts session to retrieve username $name = $_SESSION['USERNAME']; // Retrieving session username if($_SESSION['USERNAME'] == 'TEP') { $name = "The Elemental Programmer"; } else { $name = $_SESSION['USERNAME']; } $post = $_POST['post']; // The Blog entry itself $date = date("m/d/y"); $time = date("h:i A"); $title = $_POST ['title']; // Title of the blog entry $n = 994; $i = 0; $dir = '../entries/'; if ($handle = opendir($dir)) { while (($file = readdir($handle)) !== false){ if (!in_array($file, array('.', '..')) && !is_dir($dir.$file)) $i++; $n = 994 - $i; } } $new_message = "<h1 class=\"title\">$title</h1><p> $post <br><br>-$name <br>$date at $time<br><a href=\"reply.php?n=blogentry$n.php\">Comment</a> <?php session_start(); if($_SESSION['USERNAME'] == 'TEP') { echo \"<a href=\"../makepost/changepost.php?posts=blogentry$n.php\">Edit</a>\"; } ?></p><hr>\n"; // Creates file for blog entry $open_file = fopen("../entries/blogentry".$n.".php", "x"); // Enters new entry and strips the slashes fputs($open_file, stripslashes($new_message)); // Close the file fclose($open_file); ?>
  4. After trying that code, it still gave me the same error
  5. I have this parse error but I do not know where exactly the script went wrong. I am trying to put the contents of $new_message into another file that gets created. And yes, the PHP code that is inside $new_message should be there, I want it to also be inserted into the file that gets created. Error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in D:\Hosting\12059488\html\blog\makepost\makepost.php on line 36 $new_message = "<h1 class=\"title\">$title</h1><p> $post <br><br>-$name <br>$date at $time<br><a href=\"reply.php?n=blogentry$n.php\">Comment</a> <?php session_start(); if($_SESSION[\'USERNAME\'] == \'TEP\') { echo \"<a href=\"../makepost/changepost.php?posts=blogentry$n.php\">Edit</a>\"; } ?></p><hr>\n";
  6. I have a blog with the blog entries in a directory (very unsecure, I know) and on my home page I have a foreach(); function that retrieves all of the files (blog entries) from the entries directory. I've posted so many entries, my homepage is taking a very long time to load. Is there any way to paginate this foreach(); function? Here is my code foreach (glob("entries/*.php") as $filename) { include $filename; }
×
×
  • 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.