sayfalama sorgusu sorun

0 Cevap

İşte benim çağrı kodu:

function getPagingQuery($sql, $itemPerPage = 10)
{
    if (isset($_GET['page']) && (int)$_GET['page'] > 0) {
        $page = (int)$_GET['page'];
    } else {
        $page = 1;
    }

    // start fetching from this row number
    $offset = ($page - 1) * $itemPerPage;

    return $sql . " LIMIT $offset, $itemPerPage";
}

function getPagingLink($sql, $itemPerPage = 10, $strGet ="")

{
    $result        = dbQuery($sql);
    $pagingLink    = '';
    $totalResults  = dbNumRows($result);
    $totalPages    = ceil($totalResults / $itemPerPage);

    // how many link pages to show
    $numLinks      = 10;


    // create the paging links only if we have more than one page of results
    if ($totalPages > 1) {

        $self = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ;


        if (isset($_GET['page']) && (int)$_GET['page'] > 0) {
            $pageNumber = (int)$_GET['page'];
        } else {
            $pageNumber = 1;
        }

        // print 'previous' link only if we're not
        // on page one
        if ($pageNumber > 1) {
            $page = $pageNumber - 1;
            if ($page > 1) {
                $prev = " <a href=\"$self?page=$page&$strGet/\">[Prev]</a> ";
            } else {
                $prev = " <a href=\"$self?$strGet\">[Prev]</a> ";
            }    

            $first = " <a href=\"$self?$strGet\">[First]</a> ";
        } else {
            $prev  = ''; // we're on page one, don't show 'previous' link
            $first = ''; // nor 'first page' link
        }

        // print 'next' link only if we're not
        // on the last page
        if ($pageNumber < $totalPages) {
            $page = $pageNumber + 1;
            $next = " <a href=\"$self?page=$page&$strGet\">[Next]</a> ";
            $last = " <a href=\"$self?page=$totalPages&$strGet\">[Last]</a> ";
        } else {
            $next = ''; // we're on the last page, don't show 'next' link
            $last = ''; // nor 'last page' link
        }

        $start = $pageNumber - ($pageNumber % $numLinks) + 1;
        $end   = $start + $numLinks - 1;        

        $end   = min($totalPages, $end);

        $pagingLink = array();
        for($page = $start; $page <= $end; $page++)    {
            if ($page == $pageNumber) {
                $pagingLink[] = " $page ";   // no need to create a link to current page
            } else {
                if ($page == 1) {
                    $pagingLink[] = " <a href=\"$self?$strGet\">$page</a> ";
                } else {    
                    $pagingLink[] = " <a href=\"$self?page=$page&$strGet\">$page</a> ";
                }    
            }

        }

        $pagingLink = implode(' | ', $pagingLink);

        // return the page navigation link
        $pagingLink = $first . $prev . $pagingLink . $next . $last;
    }

    return $pagingLink;
}

im gibi çağrı:

$sql = "something";
$result     = mysql_query(getPagingQuery($sql, $rowsPerPage));  
$pagingLink = getPagingLink($sql, $rowsPerPage, $url);

şimdi benim url gibiyse

http://xyz/abc/list.php onun çalışma ince.

ama benim url gibi olduğunda

http://xyz/abc/list.php?action=def

i 2. sayfada tıkladıktan sonra gibi url değişiklikler http://xyz/abc/list.php?page2&

'Action = def' parçası kadar sonuç değişiklikleri gitti.

i $ _SERVER ['QUERY_STRING'] as $ strGet değeri geçmek için kullanırsanız

1. zaman o http://xyz/abc/list.php?page2&action=def gibi ok

ancak 2. zaman itibaren o http://xyz/abc/list.php?page3&page2&action=def gibi verir

böylece istenilen sonucu elde değil.

i istiyorum oysa o http://xyz/abc/list.php?page3&action=def gibi olmak

plz önceden thanxx .. yardımcı

0 Cevap