2014-09-16 3 views
0

데이터베이스의 레코드를 완벽하게 업데이트하고 데이터 테이블에 반영되지 않은 경우. 페이지를 새로 고침 할 때 데이터 테이블이 업데이트됩니다. 페이지 데이터 테이블을 새로 고치면 updated.please 도움이 필요합니다.데이터 테이블을 올바르게 업데이트하지 않지만 데이터베이스를 업데이트했습니다.

<?php 
      define('DB_SERVER', 'localhost'); // Your Database host 
      define('DB_USERNAME', 'root'); // Your Database user name 
      define('DB_PASSWORD', 'root'); // Your Database password 
      define('DB_DATABASE', 'qwer'); // Your Database Name 
      $connection = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE); // Connection 
      $sql = "SELECT nickname, email ,created_date_time,real_chips FROM users "; 
      $rs = mysqli_query($connection,$sql); 
      $str =""; 
      $data = array(); 
      while ($row = mysqli_fetch_assoc($rs)) 
      { 
       $str .= '<tr id="dialog-confirm">'; 
       $str .= '<td>'.$row["nickname"].' </td> <td>'. $row["email"].'</td><td>'. $row["created_date_time"].'</td><td>'. $row["real_chips"].'</td>'; 
       $str .= '</tr>'; 
      } 
?> 
<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
    <title>Admin demo</title> 
    <style type="text/css" title="currentStyle"> 
      @import "demo_page.css"; 
      @import "demo_table.css";    
    </style> 
    <script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.js'></script> 
    <script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script> 
    <link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css"> 
    <!--<link rel="stylesheet" type="text/css" href="/css/result-light.css"> --> 
    <script type='text/javascript' src="http://cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"></script> 
    <link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css"> 
    <script type='text/javascript' src="http://jquery-datatables-column-filter.googlecode.com/svn/trunk/media/js/jquery.dataTables.columnFilter.js"></script> 
    <script src="http://code.jquery.com/jquery-migrate-1.1.0.js"></script> 
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){ 
$(document).ready(function() { 
    $.datepicker.regional[""].dateFormat = 'yy-mm-dd'; 
    $.datepicker.setDefaults($.datepicker.regional['']); 

    drawDataTable = function() 
    { 

    $('#example').dataTable({ 
     "aoColumns": [{ 
      "sWidth": "200px" 
     }, 
     null, 
     null, 
     null] 
    }) 
     .columnFilter({ 
     sPlaceHolder: "head:before", 
     aoColumns: [{ 
      type: "text" 
     }, { 
      type: "text" 
     }, { 
      type: "date-range" 
     },{ 
      type: "text" 
     }] 
    }); 
    } 

    // call datatable for the first time when page loads 
    drawDataTable(); 

    $('#example').on("click", "tr#dialog-confirm", function() { 
     var tableData = $(this).children("td").map(function() { 
      return $(this).text(); 
     }).get(); 
     //' + $.trim(tableData[0]) + ' 

     var dynamicDialog = $('<div id="MyDialog" > <div><div style="width:150px;float:left;">Amount</div><div style="float:left;">:</div><div style="width:150px;float:left;"><input type="text" name="amount" id="amount" style="width:150px;"/><input type="text" name="nickname" id="nickname" value="'+$.trim(tableData[0])+'" style="display:none;"/></div></div><div><div style="width:150px;float:left;">Password</div><div style="float:left;">:</div><div style="width:150px;float:left;"><input type="password" name="password" id="password" style="width:150px;"/></div></div></div>'); 
     dynamicDialog.dialog({ 
      title: "Admin chips adding", 
      modal: true, 
      height: 250, 
      width: 400, 
      buttons: [{ 
       text: "Yes", 
       click: function() 
       { 
        $.ajax({ 
         type: "POST", 
         dataType: "html", 
         url: "Chips_AddedByAdmin.php", 
         cache: false, 
         data: { 
          username: $.trim(tableData[0]), 
          amount: $('#amount').val(), 
          password: $('#password').val() 
         }, 
         beforeSend: function() { 
          $('#MyDialog').html('loading please wait...'); 
         }, 
         success: function (htmldata) { 
          //destroy existing datatable 
          $('#example').dataTable().fnDestroy(); 

          //call datatable 
          drawDataTable(); 

          $('#MyDialog').html("You have successfully updated the database"); 
          dynamicDialog.dialog("close"); 

         } 
        }); 

       } 
      }, { 
       text: "No", 
       click: function (e) { 
        $(this).dialog("close"); 
       } 
      }] 
     }); 

    }); 
}); 
});//]]> 

</script> 
</head> 
<body> 
    <table id="example" class="display"> 
    <thead> 
     <tr> 
      <th style="width: 150px;">UserName</th> 
      <th style="width: 150px;">Email</th> 
      <th style="width: 180px;">Created Date</th> 
      <th style="width: 180px;">Real Chips</th> 
     </tr> 
     <tr> 
      <th style="width: 150px;">UserName</th> 
      <th style="width: 150px;">Email</th> 
      <th style="width: 180px;">Created Date</th> 
      <th style="width: 180px;">Real Chips</th> 
     </tr> 
    </thead> 
    <tbody>   
      <?php  
       echo $str; 
      ?> 
    </tbody> 
</table> 

</body> 


</html> 

그리고 아약스 dataupdate PHP는 여기에 당신이 여기에 무슨 무슨 확실하지

<?php 
require_once("configure.php"); 
echo $nickname = $_POST['username']; 
echo $amount = $_POST['amount']; 
echo $password = $_POST['password']; 

echo $sql = "SELECT * FROM users WHERE nickname ='admin' and password='$password';"; 
$rs = mysqli_query($connection,$sql); 

$numrows=mysqli_num_rows($rs); 
if($numrows > 0) 
{ 

    echo $sql = "update users set real_chips=real_chips+'$amount' where nickname='$nickname';"; 
    $rs = mysqli_query($connection,$sql); 
} 
?> 

답변

1

이지만, 이것은 내가 그것을 할 것입니다 방법과 완전히 다릅니다. 내가 전화를 할 것입니다 모두는, 내가 그 데이터 테이블을 새로하고 싶었

oTable = $("table").dataTable({ ... settings ... }); 

:

내가 다음과 같이 정의 된 데이터 테이블을 가지고 말할 수 있습니다 그것 뿐이다

oTable.fnDraw(); 

합니다.

코드에서와 같이 파기, 추가 기능 만들기 등이 필요하지 않습니다. 의사 문서를 열면 바로 할 수 있습니다.

+0

위에 게시 된 예제에서 drawDataTable() 호출이 있지만 데이터 테이블에서 호출 된 데이터 테이블은 업데이트되지 않습니다. 우리가 이것을 업데이트 할 필요가 있다는 것을 의미합니다. . 어떻게 동적으로 처리 할 수 ​​있습니까? @ Zee Tee – vamsikrishnareddy

+0

PHP 코더가 아닙니다. 죄송합니다. –

+0

감사합니다. @ zee tee – vamsikrishnareddy

관련 문제