2010-08-24 2 views
0

페이지 당 결과를 25로 제한하는 데이터베이스 검색에 사용하는 페이지 매김 기능이 있습니다. 그러나 대략 2300 개의 항목이 있고 누군가가 많은 결과 페이지의 맨 아래에 90 개 정도의 페이지 매김 링크가 생깁니다. 나는 페이징 네비게이터를 한 번에 10 페이지 만 보여줄 것을 제한하고, 페이지 spelunking에 따라 조정하고 싶습니다.페이지 매기기 기능 탐색을 페이지 당 10 개로 제한하는 방법

내 스크립트를 조정하는 방법을 잘 모르겠습니다.

도움을 주시면 감사하겠습니다.

내 현재의 기능은 그렇다 :

$ search_function는 $의 classical_guitar 이미지를 참조하는 적절한 URL을 취득하기위한 자바 스크립트 함수입니다. 여기

function generate_page_links($cur_page, $num_pages) { 
    global $search_function, $classical_guitarL, $classical_guitarR; 
    $page_links = ''; 

    // If this page is not the first page, generate the "previous" link 
    if ($cur_page > 1) { 
    $page_links .= '<a href="javascript:' . $search_function . "('', '" . ($cur_page - 1) . "');\">" . $classical_guitarL . "</a> "; 
    } 
    else { 
    $page_links .= ''; 
    } 

    // Loop through the pages generating the page number links 
    for ($i = 1; $i <= $num_pages; $i++) { 
    if ($cur_page == $i) { 
     $page_links .= ' ' . $i; 
    } 
    else { 
     $page_links .= '<a href="javascript:' . $search_function . "('', '" . $i . "');\"> " . $i . "</a> "; 
    } 

    } 

    // If this page is not the last page, generate the "next" link 
    if ($cur_page < $num_pages) { 
    $page_links .= '<a href="javascript:' . $search_function . "('', '" . ($cur_page + 1) . "');\">" . $classical_guitarR . "</a> "; 
    } 
    else { 
    $page_links .= ''; 
    } 

    return $page_links; 
} 

답변

1

, 나는 당신의 기능을 수정했습니다

<?php 

function generate_page_links($cur_page, $num_pages) 
{ 
    global $search_function, $classical_guitarL, $classical_guitarR; 
    $page_links = ''; 


    // If this page is not the first page, generate the "previous" link 
    if ($cur_page > 1) 
    { 
     $page_links .= '<a href="javascript:' . $search_function . "('', '" . ($cur_page - 1) . "');\">" . $classical_guitarL . "</a> "; 
    } 
    else 
    { 
     $page_links .= ''; 
    } 

    $pager_num = 7; // How many page number you wish to display to the left and right sides of the current page 
    $index_start = ($cur_page - $pager_num) <= 0 ? 1 : $cur_page - $pager_num; 
    $index_finish = ($cur_page + $pager_num) >= $num_pages ? $num_pages : $cur_page + $pager_num; 
    if (($cur_page - $pager_num) > 1) { $page_links .= '...'; } // Display ... when there are more page items than $page_num 

    // Loop through the pages generating the page number links 
    // NOTE: I've modified the for index pointers here... 
    for ($i = $index_start; $i <= $index_finish; $i++) 
    { 
     if ($cur_page == $i) 
     { 
      $page_links .= ' ' . $i; 
     } 
     else 
     { 
      $page_links .= '<a href="javascript:' . $search_function . "('', '" . $i . "');\"> " . $i . "</a> "; 
     } 
    } 

    if (($cur_page + $pager_num) < $num_pages) { $page_links .= '...'; } // Display ... when there are more page items than $page_num 

    // If this page is not the last page, generate the "next" link 
    if ($cur_page < $num_pages) 
    { 
     $page_links .= '<a href="javascript:' . $search_function . "('', '" . ($cur_page + 1) . "');\">" . $classical_guitarR . "</a> "; 
    } 
    else 
    { 
     $page_links .= ''; 
    } 

    return $page_links; 
} 

?> 

이 도움이됩니다 희망 ...

+0

너무 감사합니다! 이것은 완벽하게 작동했습니다. – MBguitarburst