Jump to content

little help would be appreciated


drisate

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

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.