2017-02-25 62 views

回答

0

您需要使用AJAX的,那是方式使用jQuery幫助您在實時的變化

+0

感謝Carlos Quintero。請問你能幫我完整的腳本嗎? – nwafeolie

+0

好了給我你的代碼來分析它 –

+0

<表CELLSPACING = 「2」 的cellpadding = 「2」 BORDER = 「2」> ​​ ​​ ​​ nwafeolie

0

我做了一些小改動來執行使用jQuery這個動作

<body> 
<table cellspacing="2" cellpadding="2" border="2"> 
    <?php $sql = "Select * from prject_topic"; $result = mysqli_query($conn, $sql); 
    while($row = mysqli_fetch_assoc($result)) { ?> 
     <tr> 
      <td><?php echo $row['lecturer_name'];?></td> 
      <td><?php echo $row['topic'];?></td> 
      <td><span class="actu" id="<?php echo $row['project_id'];?>"> 
        <?php echo $row['status'];?> 
       </span> 
      </td> 
     </tr> <?php } ?> 
    </table> 


<script type="text/javascript"> 
    $(function(){ 
     //We capture the Click in the user item 
     $(".actu").on('click', function(){ 
      //We take the ide of this item 
      var id = $(this).attr('id'); 
       //We check the current status of the user 
       if($(this).html() == "Deactivate"){ 
        var est = "Activate"; 
       }else{ 
        var est = "Deactivate"; 
       } 

      //We made a request of type ajax sending by post the id for its update 
      $.post('#.php', 
         { 
          'id':id, 
          'est':est 
         }, 
         //We received the response from our php file which may be a code as in the example... 
         function(data){ 

          if(data=="200"){ 
           //If yes, update the content of the selected item in real time 
           $("#"+id).html('Deactivate'); 
          }else{ 
           //In case of error, we send the information 
           alert("Unable to disable user"); 
          } 

        }) 
     }) 
    }) 
</script> 
</body> 

該代碼是爲了您的理解而編寫的

+0

在響應函數中,您必須將選擇代碼的印象放在變量est中,我錯過了那裏... –

+0

例如:'$(「#」+ id).html(est);' –

+0

卡洛斯感謝這個劇本。我成功使用mysqli更新功能。 – nwafeolie

相關問題