sql >> Database >  >> RDS >> Mysql

Zoeken naar geavanceerd php/mysql pagineringscript

Probeer dit eens,

function generatePagination($currentPage, $totalPages, $pageLinks = 5)
{
    if ($totalPages <= 1)
    {
        return NULL;
    }

    $html = '<ul class="pagination">';

    $leeway = floor($pageLinks / 2);

    $firstPage = $currentPage - $leeway;
    $lastPage = $currentPage + $leeway;

    if ($firstPage < 1)
    {
        $lastPage += 1 - $firstPage;
        $firstPage = 1;
    }
    if ($lastPage > $totalPages)
    {
        $firstPage -= $lastPage - $totalPages;
        $lastPage = $totalPages;
    }
    if ($firstPage < 1)
    {
        $firstPage = 1;
    }

    if ($firstPage != 1)
    {
        $html .= '<li class="first"><a href="./?p=1" title="Page 1">1</a></li>';
        $html .= '<li class="page dots"><span>...</span></li>';
    }

    for ($i = $firstPage; $i <= $lastPage; $i++)
    {
        if ($i == $currentPage)
        {
            $html .= '<li class="page current"><span>' . $i . '</span></li>';
        }
        else
        {
            $html .= '<li class="page"><a href="./?p=' . $i . '" title="Page ' . $i . '">' . $i . '</a></li>';
        }
    }

    if ($lastPage != $totalPages)
    {
        $html .= '<li class="page dots"><span>...</span></li>';
        $html .= '<li class="last"><a href="./?p=' . $totalPages . '" title="Page ' . $totalPages . '">' . $totalPages . '</a></li>';
    }

    $html .= '</ul>';

    return $html;
}


  1. Bestandsopslag voor webtoepassingen:bestandssysteem versus DB versus NoSQL-engines

  2. Fout bij invoegen in sql-database met php

  3. Hoe expressie in select-statement in Postgres te evalueren

  4. mysql-query om alles behalve iets te selecteren