Jump to content

Recommended Posts


Hey guys ia m trying to create a code that seperates a database result into pages. The code works greate but i am bloking on the part to show only 9 pages at the time in the page menu. Ex:

 

At page 2 the output would look like this

<< | < | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | > | >>

 

At page 10 the output would look like this

<< | < | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | > | >>

 

This is the code i made so fare ... The total number of rows is $artiste_nombre and the total number per page is $nombre_par_page the current page is $_GET


 

I just don't get how to make this working ...

 

$maxPage = ceil($artiste_nombre / $nombre_par_page);

    for ($page = 1; $page <= $maxPage; $page++) {
        if ($page == $num_page) {
            $nav .= '<td class="greytable2" align="center" width="25">'.$page.'</td>';
            
        } else {
            $nav .= '<td class="greytable2" align="center" width="25"><a href="index.php?mod=page&id='.$_GET[id].'&page='.$page.'">'.$page.'</a></td>';
        }
    }

    if ($num_page > 1) {
        $page = $num_page - 1;
        $prev = '<td class="greytable2" align="center" width="25"><a href="index.php?mod=page&id='.$_GET[id].'&page='.$page.'"><</a></td>';
        
        $first = '<td class="greytable2" align="center" width="25"><a href="index.php?mod=page&id='.$_GET[id].'&page=1"><<</a></td>';
    } else {
        //$prev = ' ';
        //$first = ' ';
    }

    if ($num_page < $maxPage) {
        $page = $num_page + 1;
        $next = '<td class="greytable2" align="center" width="25"><a href="index.php?mod=page&id='.$_GET[id].'&page='.$page.'">></a></td>';

        $last = '<td class="greytable2" align="center" width="25"><a href="index.php?mod=page&id='.$_GET[id].'&page='.$maxPage.'">>></a></td>';
    } else {
        //$next = ' ';
        //$last = ' ';
    }

    // Navigation
    print ("$first $prev $nav $next $last");

Link to comment
https://forums.phpfreaks.com/topic/160697-little-help-would-be-appreciated/
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.