Pagination script error - Why are you jumping to the first page?

PHP student. The script display at the bottom seems to work normally, but the problem is that on each page of 20 entries, when I select several lines (using checkboxes) and press the SUBMIT button, the display of 20 entries goes to page 1. rows are selected without problems but I can’t understand why it is returning to page 1.

Is the problem obvious in the script below? Thank!

//-----------------|
// Add pagination.
//-----------------|

$nAdjacentPages =  3; 

// If the current page number is greater than 1, then display:
// "<<" and "<" (i.e., << < ).

if ($nCurrentPage > 1) 
   {
      echo " <a href = 
         '{$_SERVER['PHP_SELF']}?nCurrentPage=1'> << </a> " ;
      $nPreviousPage = $nCurrentPage - 1 ;
      echo " <a href = 
         '{$_SERVER['PHP_SELF']}?nCurrentPage=$nPreviousPage'> < </a> ";
   }   

// Appearance of page links when viewing page 5:
//     << <  2  3  4  [5]  6  7  8  > >>  

for ( $x = ( $nCurrentPage - $nAdjacentPages ) ; 
      $x < ( ( $nCurrentPage + $nAdjacentPages ) + 1 ) ; 
      $x++ ) 
   {
      // if it a valid page number...

      if ( ( $x > 0 ) and ( $x <= $nTotalPages ) ) 
         {
            // If on current page, 'highlight' but do not link.
            // If not current page, make it a link.

            if ( $x == $nCurrentPage ) 
               {
                  echo " [<b> $x </b>] " ;
               } 
            else 
               {
                  echo " <a href=
                     '{$_SERVER['PHP_SELF']}?nCurrentPage=$x'> $x </a> " ;
               } 
         } 
   } 

// If not last page, show '>' and '>>' links.

if ( $nCurrentPage != $nTotalPages ) 
   {
      $nNextPage = $nCurrentPage + 1;
      echo " <a href = 
         '{$_SERVER['PHP_SELF']}?nCurrentPage=$nNextPage'> > </a> ";
      echo " <a href = 
         '{$_SERVER['PHP_SELF']}?nCurrentPage=$nTotalPages'> >> </a> ";
   } 
?>
+3
source share
2 answers

It goes to page 1 because your form actionis probably simple script.php.

GET, nCurrentPage .

POST, ?nCurrentPage=$nCurrentPage ( - ...) action ( , , script.php?nCurrentPage=3), script, $_POST $_GET, , , .

0

, , , nCurrentPage.

0

Source: https://habr.com/ru/post/1732947/


All Articles