2012-01-20 3 views
0

내 검색 결과 페이지에서 사용자는 왼쪽의 버튼을 사용하여 검색 결과를 수정할 수 있습니다. 이 버튼들은 jquery를 사용하여 div의 결과를 업데이트합니다. 그러나 jquery를 사용하여 결과를 다시 호출하고 div에 에코하면 NEXT PAGE, LAST PAGE 등의 링크가 제대로 작동하지 않습니다. 이것은 내가 사용하고 매김 클래스입니다 : 결과가 search.php에 표시되며, jqueried 수정 결과를 search_again.php에서 호출하는 경우PHP 페이지 매김 클래스 및 AJAX/JQuery 링크 오류

class pagination 
    { 
    var $page = 1; // Current Page 
    var $perPage = 10; // Items on each page, defaulted to 10 
    var $showFirstAndLast = false; // if you would like the first and last page options. 

    function generate($array, $perPage = 10) 
    { 
     // Assign the items per page variable 
     if (!empty($perPage)) 
     $this->perPage = $perPage; 

     // Assign the page variable 
     if (!empty($_GET['page'])) { 
     $this->page = $_GET['page']; // using the get method 
     } else { 
     $this->page = 1; // if we don't have a page number then assume we are on the first page 
     } 

     // Take the length of the array 
     $this->length = count($array); 

     // Get the number of pages 
     $this->pages = ceil($this->length/$this->perPage); 

     // Calculate the starting point 
     $this->start = ceil(($this->page - 1) * $this->perPage); 

     // Return the part of the array we have requested 
     return array_slice($array, $this->start, $this->perPage); 
    } 

    function links() 
    { 
     // Initiate the links array 
     $plinks = array(); 
     $links = array(); 
     $slinks = array(); 

     // Concatenate the get variables to add to the page numbering string 
     if (count($_GET)) { 
     $queryURL = ''; 
     foreach ($_GET as $key => $value) { 
      if ($key != 'page') { 
      $queryURL .= '&'.$key.'='.$value; 
      } 
     } 
     } 

     // If we have more then one pages 
     if (($this->pages) > 1) 
     { 
     // Assign the 'previous page' link into the array if we are not on the first page 
     if ($this->page != 1) { 
      if ($this->showFirstAndLast) { 
      $plinks[] = ' <a href="?page=1'.$queryURL.'">&laquo;&laquo; First </a> '; 
      } 
      $plinks[] = ' <a href="?page='.($this->page - 1).$queryURL.'">&laquo; Prev</a> '; 
     } 

     // Assign all the page numbers & links to the array 
     for ($j = 1; $j < ($this->pages + 1); $j++) { 
      if ($this->page == $j) { 
      $links[] = ' <a class="selected">'.$j.'</a> '; // If we are on the same page as the current item 
      } else { 
      $links[] = ' <a href="?page='.$j.$queryURL.'">'.$j.'</a> '; // add the link to the array 
      } 
     } 

     // Assign the 'next page' if we are not on the last page 
     if ($this->page < $this->pages) { 
      $slinks[] = ' <a href="?page='.($this->page + 1).$queryURL.'"> Next &raquo; </a> '; 
      if ($this->showFirstAndLast) { 
      $slinks[] = ' <a href="?page='.($this->pages).$queryURL.'"> Last &raquo;&raquo; </a> '; 
      } 
     } 

     // Push the array into a string using any some glue 
     return implode(' ', $plinks).implode($this->implodeBy, $links).implode(' ', $slinks); 
     } 
     return; 
    } 
    } 
?> 

, 페이지 매김 링크 (NEXT, LAST 등) 따를 것 search.php로 업데이트하고 search_again.php로 업데이트하지 마십시오. 대신 검색의 결과 사업부에 국한되는,

$slinks[] = ' <a href="'.$_SERVER['PHP_SELF'].'?page='.($this->page + 1).$queryURL.'"> Next &raquo; </a> '; 

을하고 어느 정도 작동합니까,하지만이 링크를 클릭 :

$slinks[] = ' <a href="?page='.($this->page + 1).$queryURL.'"> Next &raquo; </a> '; 
이에

:

나는이 변화 시도 .php이면 전체 페이지 자체에로드됩니다. 이 경험이있는 사람이 있습니까? 감사합니다

편집 : 여기 내 JQuery와 있습니다 :

$(document).ready(function(){ 
$("#button").click(function(){ 
    var miles = $('#miles').val(); 
    $.ajax({ 
      url: 'thetestsession.php', //the variable miles is set being $_GET 
      data: 'miles=' + miles, //on this page and set to session 
      type: 'GET',    //variable. miles is variable 
               //that a user can modify his 
               //search with. 
      success: function(results) { 
       $("#results").html(results); //#results is the div 
       //alert("Ok."); 
      } 
     });        //then i load thetestresults.php 
    $("#results").load('thetestresults.php'); //this is the page where the re-query 
     return false;      //takes place. 
});            
}); 
+0

jQuery를 게시 할 수 있습니까? – MyStream

+0

원래 게시물에 추가했습니다. – Norse

답변

1

당신이 당신의 PHP의 링크 태그에 ID "#button"을 추가하면 그것은 작동하지 않을 수 있습니다. 나는 네가 잊어 버린 것 같은데 ... 내가 틀렸다면 나에게 정정해라! 인사말

+0

Like'$ slinks [] = ' Next »'; 이것은 작동하지 않았다. – Norse

+0

CSS ID 태그를 설정해야합니다 :'$ slinks [] = ' Next »';' – CyrillC