Jump to content

pagination without database


dezkit

Recommended Posts

This is an old script I created when I started out in PHP

<?php

$page = (isset($_GET['page'])) ? $_GET['page'] : 0;

$content = "Hello, World!
{newpage}
Hey! A new page...
{newpage}
Kool
{newpage}
Another too!
{newpage}
Umm, bye!";

$pages = explode('{newpage}', $content);

echo $pages[$page].'<br>';

$total_pages = count($pages);

$prevpage = $page - 1;
$nextpage = $page + 1;

if ($page > 0)
{
   if($page < $total_pages - 1)
   {
       $page_div = ' | ';
   }
   else
   {
       $page_div = '';
   }

   echo "<a href=\"?page={$prevpage}\">Prev</a>{$page_div}";
}

if ($nextpage < $total_pages)
{
 echo "<a href=\"?page={$nextpage}\">Next</a>";
}

?>

Link to comment
Share on other sites

Your question is unanswerable.  I suggest you re-think your problem and explain it in much greater detail.

 

I literally just laughed at myself.

 

This is what i mean: How do i make a pagination out of that, so that each page displays 10 numbers, and there are 10 pages

Link to comment
Share on other sites

Ahhh yeah, that is just what i want, but, i need it to have a while loop to up to 1000 numbers? :P Thankss

Change

$content = "Hello, World!
{newpage}
Hey! A new page...
{newpage}
Kool
{newpage}
Another too!
{newpage}
Umm, bye!";

$pages = explode('{newpage}', $content);

echo $pages[$page].'<br>';

to

$content = range(1, 1000);

$pages = array_chunk($content, 25);

echo implode('<br />', $pages[$page]).'<hr>';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.