[Solved] pagination for custom PHP site [closed]


It all depends on where and how your pages are stored though! if you do that with a database, you would need to check if the $pagenum ( which we don’t see defined anywhere ) has previous/next pages… and based on that you draw you +/- 5 pages anchors! preferably doing some looping!

On the other hand if you are not using any database and just want to show some content based on the ?pagenum=(number) which is what you seem to do here! you would need to get the current page via $_GET[‘pagenum’] once the user is on the new page! so that the content displays properly!

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

well then you simply do something like :

echo "<a href=\"https://stackoverflow.com/questions/13547121/{$_SERVER["PHP_SELF']}?pagenum=$first\">first</a>";

for ( $i = $pagenum-5; $i <= $pagenum+5; ++$i ) // check if the pages exist as well somewhere ;)
{
    if ( $pagenum != $i ) 
    {
        echo "<a href=\"https://stackoverflow.com/questions/13547121/{$_SERVER["PHP_SELF']}?pagenum=".($i)."\">$i</a>";
    }
    else
    {
        echo "<a href=\"#\">Current</a>";
    }
}

echo "<a href=\"https://stackoverflow.com/questions/13547121/{$_SERVER["PHP_SELF']}?pagenum=$last\">last</a>";

if that “method” is too basic to you have a look at this ones simple-php-mysql-pagination, how-to-paginate-data-with-php, basic-pagination

2

solved pagination for custom PHP site [closed]