2017-09-09 1 views
0

아래의 코드는 정상적인 페이지 매김을 수행하고 있습니다. Ajax로 페이지 매김을 만드는 방법에 대한 지침을 원합니다. PHP를 사용하면서 머리가 여전히 혼란 스럽습니다.PHP OO - Ajax 페이지 매김

페이지 매김 링크에서 ajax를 사용하려면 어떻게해야합니까? ".$self."?page_no=".$next."

테이블의 끝에 아래의 코드

index.php를

<?php 
     $query = "SELECT * FROM users ORDER BY id DESC";  
     $records_per_page=7; 
     $newquery = $crud->paging($query,$records_per_page); 
     $crud->dataview($newquery); 
    ?> 
    <tr> 
     <td colspan="7" align="center"> 
      <nav aria-label="Page navigation example"> 
      <?php $crud->paginglink($query,$records_per_page); ?> 
      </nav> 
     </td> 
    </tr> 

class.crud.php

public function paginglink($query,$records_per_page) 
    { 

     $self = $_SERVER['PHP_SELF']; 

     $stmt = $this->db->prepare($query); 
     $stmt->execute(); 

     $total_no_of_records = $stmt->rowCount(); 

     if($total_no_of_records > 0) 
     { 
      ?><ul class="pagination"><?php 
      $total_no_of_pages=ceil($total_no_of_records/$records_per_page); 
      $current_page=1; 
      if(isset($_GET["page_no"])) 
      { 
       $current_page=$_GET["page_no"]; 
      } 
      if($current_page!=1) 
      { 
       $previous =$current_page-1; 
       echo "<li class='page-item'><a class='page-link' href='".$self."?page_no=1'>First</a></li>"; 
       echo "<li class='page-item'><a class='page-link' href='".$self."?page_no=".$previous."'>Back</a></li>"; 

      } 
      for($i=1;$i<=$total_no_of_pages;$i++) 
      { 
       if($i==$current_page) 
       { 
        echo "<li class='page-item'><a class='page-link' href='".$self."?page_no=".$i."' style='color:red;'>".$i."</a></li>"; 
       } 
       else 
       { 
        echo "<li class='page-item'><a class='page-link' href='".$self."?page_no=".$i."'>".$i."</a></li>"; 
       } 
      } 
      if($current_page!=$total_no_of_pages) 
      { 
       $next=$current_page+1; 
       echo "<li class='page-item'><a class='page-link' href='".$self."?page_no=".$next."'>Next</a></li>"; 
       echo "<li class='page-item'><a class='page-link' href='".$self."?page_no=".$total_no_of_pages."'>Last</a></li>"; 
      } 
      ?></ul><?php 
     } 
    } 

나는 아약스를 채우는 방법을 정확히 모르는 헤더에 있음

<script> 
function() { $.ajax({ 
    url: url, 
    type: "GET", 
    data: , 
    success: , 
    error:    
    }); 
} 
</script> 
(210)는

은 이미 내가 두 개의 부트 스트랩 열이

진화 할 수있었습니다 도움을 --- 업데이트 --- 내가 어떻게 아약스의 작품을 배우고

,의는 등록 양식과 왼쪽 이미 등록되어 있고 페이지 매김을 포함하고있는 목록의 오른쪽. 페이지 번호 (<table #content-of-table> 태그의 테이블 태그에 ID를 넣음)를 클릭하면 페이지 전체가 복제되고 페이지 매김이 작동하지만 전체 화면 내용이 테이블 태그에 나타납니다.

나는 href에서 URL을 가져다가 어디에서 시작 JQuery와

$('.page-link').click(function (e) { 
    e.preventDefault(); 

    var url = $(this).data('href'); 

    $.ajax({ 
     url: url, 

     success: function (response) { 
       $('#content-of-page').html(response) 
     } 
    }); 
}) 
+0

정확히 무엇을 하시겠습니까? 이 순간에 무엇이 작동하지 않습니까? 아약스는 당신에게 무엇을해야합니까? 조회수는 16이고 의견이나 답변은 없으며 문제를 설명 할 수 있습니까? 고맙습니다. – jagb

답변

0

data-href

"<a href='#' class='page-link' data-href='".$self."?page_no=".$previous."'>Back</a>"; 

에 넣어.

엄밀히 말하면, 이것은 OOP 그 자체와는 거의 관계가 없으며, 단지 믿기 어려울 정도입니다.

일반적으로 ajax는 클라이언트 측에서 서버 측과 상호 작용할 수 있도록하기위한 용도로 사용됩니다. 페이지가 클라이언트 측에서 렌더링되면 서버 측과 상호 작용할 수 있습니다.

실제로 이것은 대부분 아약스를 사용하여 데이터베이스와 같은 리소스에 액세스 한 다음 페이지 새로 고침없이 페이지 내용을 업데이트 할 수있는 것으로 요약됩니다. 그것을 모든 작업, 자바 스크립트 또는 JQuery와의 비트를 만드는 것 마침내

<!-- since we use it below, your include of jquery - but if you do it with js it is not necessary --> 
<div id="somepage"> 
    Some text that was rendered normally on landing. 
    <div id="thecontentsIwanttoupdatewithajax"> 
     Some contents rendered on landing. 
    </div> 
    <button onclick="updateallthethings();">A button that updates stuff</button> 
</div> 

과 :

<?php 
//file somephpfile.php 
$somevalueyouwillget = $_POST["somevaryouwanttopass"]; 

echo $somevalueyouwillget; 
?> 

일부 HTML을 :

은 우리가 PHP의 비트를 보자. 나 자신 (당신이 그렇게 성공, 실패를 처리해야 그냥 예) $ .post를 사용하려면 :

function updateallthethings() { 
    $.post('somephpfile.php', { somevaryouwanttopass: 'duuuude', orsomearrayinstead: { varone : valone, vartwo: valtwo } }, function(out) { 
     console.log(out); //debugging saves millions of lives every year 
     //"out" is ANYTHING that was rendered on the php side of things. 
     //for our example we use that to update the contents of our div - in your case, to replace page 1 with page 2. 
     $("#thecontentsIwanttoupdatewithajax").html(out); 
    }); 
} 

결과는 어느 이것은 간단히 말해서 그 것이다

<div id="thecontentsIwanttoupdatewithajax"> 
    duuuude 
</div> 

될 것입니다 . 그것은 의미가 있습니까?

+0

대단히 감사합니다. 예, 제 질문이 업데이트되었습니다. – Gislef