2011-07-30 1 views
0
<style type="text/css">@import url("cstyle.css");</style> 
<style type="text/css">@import url("style.css");</style> 
<script type="text/javascript"> 
function deleteComment(id) 
{ 
    xmlhttp=new XMLHttpRequest(); 
    xmlhttp.open("GET","deleteComment.php?id="+id,true); 
    xmlhttp.send(); 
} 
$(document).ready(function() 
{ 
    deleteComment(id); 

}); 
</script> 
<?php 
include_once("pass.php"); 
include("common.php"); 

class ComA 
{ 
    static function reportComment() 
    { 
     $query = mysql_query("SELECT * FROM comments WHERE Flag =1"); 
     $number=mysql_num_rows($query); 
     // number of rows to show per page 
     $rowsperpage = 15; 
     // find out total pages 
     $totalpages = ceil($number/$rowsperpage); 
     // get the current page or set a default 
     if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) 
     { 
      // cast var as int 
      $currentpage = (int) $_GET['currentpage']; 
     } 
     else 
     { 
      // default page num 
      $currentpage = 1; 
     } 
     //if current page is greater than total pages... 
     if ($currentpage > $totalpages) 
     { 
      // set current page to last page 
      $currentpage = $totalpages; 
     } 
     //if current page is less than first page... 
     if ($currentpage < 1) 
     { 
      // set current page to first page 
      $currentpage = 1; 
     } 
     //the offset of the list, based on current page 
     $offset = ($currentpage - 1) * $rowsperpage; 
     // get the info from the db 
     // while there are rows to be fetched... 
     $sql = mysql_query("SELECT * FROM comments WHERE Flag = 1 ORDER BY id DESC LIMIT $offset, $rowsperpage"); 
     ?> 
     <div id="count"> 
     <div id="title"><b>Edit Reported Comments</b></div> 
     <?php 
     if($number==1) 
      echo $number . " COMMENT"; 
     else 
      echo $number . " COMMENTS"; 
     ?> 
     </div> 
     <?php 
     while ($content = mysql_fetch_assoc($sql)) 
     { 
      ?> 
      <div id="delete"> 
      <?php $javaid=$content['id']; ?> 
       <a href="<?php $_GET['location'] ?>" onClick="deleteComment(<?php echo $javaid ?>)" ><img src="_" onmouseover="_" onmouseout="_"></a> 
      </div> 
      <div id="comment"> 
      <?php 
      echo $content['username'] . " <br/> " ; 
      ?> 
      <div id="timestamp"> 
      <?php 
      echo "Posted " . $content['date'];  
      ?> 
      </div> 
      <?php 
      echo $content['comment']; 
      ?> 
      </div> 
      <div class="greyRule"><hr /></div> 
      <?php 
     } // end while 

     /****** build the pagination links ******/ 
     // range of num links to show 
     $range = 3; 
     ?> 
     <div id="page"> 
     <?php 
     // if not on page 1, don't show back links 
     if ($currentpage > 1) 
     { 
      ?> 
      <a href="<?php echo $_GET['location'] ?>&currentpage=1" class="blue"><< first </a> 
      <?php 
      // get previous page num 
      $prevpage = $currentpage - 1; 
      ?> 
      <a href="<?php echo $_GET['location'] ?>&currentpage=<?php echo $prevpage ?>" class="blue">< previous </a> 
      <?php 
     } 
     // loop to show links to range of pages around current page 
     for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) 
     { 
      // if it's a valid page number... 
      if (($x > 0) && ($x <= $totalpages)) 
      { 
       // if we're on current page... 
       if ($x == $currentpage) 
       { 
       // 'highlight' it but don't make a link 
       echo " <b>$x</b> "; //needs to be RIGHT ALIGNED 
       // if not current page... 
       } 
       else 
       { 
       // make it a link 
       ?> 
       <a href="<?php echo $_GET['location'] ?>&currentpage=<?php echo $x ?>" class="blue"> <?php echo $x?></a> 
       <?php 
       } // end else 
      } // end if 
     } // end for       
     // if not on last page, show forward and last page links   
     if ($currentpage != $totalpages && $totalpages!=0) 
     { 
      // get next page 
      $nextpage = $currentpage + 1;   
      ?> 
      <a href="<?php echo $_GET['location'] ?>&currentpage=<?php echo $nextpage ?>" class="blue"> next ></a> 
      <a href="<?php echo $_GET['location'] ?>&currentpage=<?php echo $totalpages ?>" class="blue"> last >></a> 
      <?php 
     } 
     ?> 
     </div> 
     <?php 
    } 
} 
ComA::reportComment(); 
?> 
+0

이 자바 스크립트 인 칼레를 d by onClick은 ajax 요청이며 php 함수 인 reportComment 자체가 다른 파일에서 ajax에 의해 호출되고 있습니다. –

답변

0

잘못된 방법으로 XmlHttpRequest를 사용하고 있습니다. 더 좋은 방법이 같은 것을 사용하는 것입니다 - 당신이 jQuery를 사용하여 작업하는 경우, 당신은 페이지로드 deleteComment()를 호출하지 버튼을

+0

이것은 호출되고있는 함수입니다.

0

을 클릭 또한 http://api.jquery.com/category/ajax/ , 그것은 아주 간단 :

은 삭제 버튼을 변경

이 같은 뭔가 :

<a class="delete_btn" rel="<?php echo $comment_id; ?>" href="#"><img src="_" onmouseover="_" onmouseout="_"></a> 

하고 그 아래 어딘가에이 작은 스크립트를 넣어 :

<script> 
    $('.delete_btn').click(function() { 
    var id = $(this).attr('rel'); 
    $.get('deleteComment.php', {'id' : id}, function(data) { 
     $('#div_with_the_deleted_comment').html('This comment was deleted.'); 
     return false; 
    } 
    }); 
</script> 
+0

시도했지만 작동하지 않았습니다. import 문 을 추가했습니다. 다른 일을해야합니까? –

+0

nvm 훨씬 간단한 해결책으로 문제를 해결했습니다. 필자는 링크 href를 사용하여 함수를 직접 호출 한 다음 해당 페이지로 다시 리디렉션했습니다. 그래도 모든 도움을 주셔서 감사합니다. –

+0

@Gavin 판매자 좋은 것을 듣고;) 오신 것을 환영합니다! – Quasdunk

관련 문제