2013-10-15 4 views
2

페이지 매김에 문제가 있습니까? 10 개 항목 만 표시하는 방법은 무엇입니까? 구글에서 이런 식으로 할 수 있어요 - 숫자가 +5 씩 증가 했나요?페이지 매기기 PHP 만 10 개 항목

enter image description here

<?php 
// Make the links to other pages, if necessary. 
if ($pages > 1) { 

    echo '<br /><p>'; 
    $current_page = ($start/$display) + 1; 

    // If it's not the first page, make a Previous button: 
    if ($current_page != 1) { 
     echo '<a href="list_photos_4.php?s=' . ($start - $display) . '&p=' . $pages . '&sort=' . $sort . '">Previous</a> '; 
    } 

    // Make all the numbered pages: 
    for ($i = 1; $i <= $pages; $i++) { 
     if ($i != $current_page) { 
      echo '<a href="list_photos_4.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> '; 
     } else { 
      echo $i . ' '; 
     } 
    } // End of FOR loop. 

    // If it's not the last page, make a Next button: 
    if ($current_page != $pages) { 
     echo '<a href="list_photos_4.php?s=' . ($start + $display) . '&p=' . $pages . '&sort=' . $sort . '">Next</a>'; 
    } 

    echo '</p>'; // Close the paragraph. 

} // End of links section. 
?> 

답변

2

시도 :

// Make all the numbered pages: 
    for ($i = 1; $i <= $pages; $i++) {  
     if ($i != $current_page) { 
      $distance = $current_page - $i; 
      if (abs($distance) < 5){ 
       echo '<a href="list_photos_4.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> '; 
      } 
     } else { 
      echo $i . ' '; 
     } 
    } // End of FOR loop 

본인에게 유용합니다.

+0

안녕하세요, 답장을 보내 주셔서 감사합니다. SCREAM : 오류 억제가 무시되었습니다 알림 : 정의되지 않은 변수 : C에서 : 186 행 - 186 줄에 "$ ($ i! = $ current_page) {" –

+0

@ Mantykora7 그냥 루프에 내 솔루션을 넣어 \ wamp \ www \ dwwithphp \ public \ admin \ list_photos_4.php : for ($ i = 1 ; $ i <= $ pages; $ i ++) {// 내 답변} 방금 ​​내 대답을 편집했습니다. 작동해야합니까 – Adam

+0

예, 맞습니다, 잘못된 붙여 넣기, 잘 작동, 시간과 답변을 주셔서 감사합니다 :) –

0

변경이이에

// Make all the numbered pages: 
for ($i = 1; $i <= $pages; $i++) { 

이에 섹션 (모든 페이지 번호를 확인)을 변경하는

if ($current_page <= 5) $first_page = 1; 
else if ($pages - $current_page < 10) $first_page = $pages - 10; 
else $first_page = $current_page - 5; 

// Make up to 10 numbered pages: 
for ($i = $first_page; $i < ($first_page + 10); $i++) { 
+0

안녕하세요 - $ display = 2; - 항목 25, $ display = 10 items 10과 비슷한 것을 보여줍니다 Previous -5 -4 -3 -2 -1 0 1 2 3 4 다음 –

+0

어떤 $ 표시가 될 것인지 잘 모르겠습니다. 즉,'$ current_page = ($ start/$ display) + 1;'이 이상하게 보입니다. $ current_page는 아마'(int) $ _GET [ 's']'이어야합니다. 귀하의 링크 구조를 이해하는 시간. 정렬 순서와 페이지 번호 만 전달해야하며 페이지 수는 서버에서 결정하고 브라우저에서 보내지 않아야합니다. 미세한 세부 사항을 파악하려면 전체 코드/논리를 정리해야합니다. –

+0

시간과 답변을 주셔서 감사합니다 - 이미 붕괴를 해결했습니다 –

0
<?php 
// Make the links to other pages, if necessary. 
if ($pages > 1) { 

    // (...) 

    $first_disp_page = $cutrrent_page - 5 < 1 ? 1 : $current_page - 5; 
    $last_disp_page = $current_page + 5 > $pages ? $pages : $current_page + 5; 

    // Make all the numbered pages: 
    for ($i = $first_disp_page; $i <= $last_disp_page; $i++) { 
     if ($i != $current_page) { 
      echo '<a href="list_photos_4.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> '; 
     } else { 
      echo $i . ' '; 
     } 
    } // End of FOR loop. 

    // (...) 

} // End of links section. 
?> 
+0

시간과 답변을 주셔서 감사합니다 :) –