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>";
}

?>

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

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>';

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.