首页 > 解决方案 > TableEdit 插件 - 同一页面上的两个表 - TableEdit 插件仅在两个表都有数据时工作

问题描述

我有一个 php 网页,其中有两个结果表。我已应用 TablEdit 插件来添加实时编辑/删除功能。仅当两个表都有结果时,它才能完美运行,如果其中任何一个为空,则 TablEdit 插件(不出现保存/删除)不起作用。

我已经为每个表分隔了 $(document).ready(function(){ } 并将它们放在两个不同的块中。但同样的问题。

<!-- UNPAID TABLE -->
$id = $_GET ['id'];
$query = "SELECT * FROM dues INNER JOIN institutions ON institutions.id = 
dues.idfk and dues.idfk ='$id' and dues.dstatus ='Unpaid'";


$data = mysqli_query($con,$query);
$total = mysqli_num_rows ($data);

if($total != 0)
{
?>

<table id="unpaid_table" class="table table-bordered">
<thead>
<tr style='text-align: center;'>
<th style='display: none;'>DID</th>
<th>Year</th>
<th>Amount</th>
<th>Penalty</th>
<th>Total Dues</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php

while ($result = mysqli_fetch_assoc($data))
{

echo "
      <tr style='text-align: center;'>                      
  <td style='display: none;'>".$result ['did']."</td>                                        
      <td>".$result ['year']."</td>                                      
      <td>".$result['amount']."</td>                                         
      <td>".$result['penalty']."</td>                                        
      <td>".$result['total']."</td>                                      
      <td>".$result['dstatus']."</td>                                    
      </tr>";                                       
  }
 }
else
{
  echo "<div style='color:red;'>No Records</div>";
}
?>
</tbody>            
</table>


<!-- PAID TABLE -->
$id = $_GET ['id'];
$query = "SELECT * FROM dues INNER JOIN institutions ON institutions.id = 
dues.idfk and dues.idfk ='$id' and dues.dstatus ='Paid'";


$data = mysqli_query($con,$query);
$total = mysqli_num_rows ($data);

if($total != 0)
{
?>

<table id="paid_table" class="table table-bordered">
<thead>
<tr style='text-align: center;'>
<th style='display: none;'>DID</th>
<th>Year</th>
<th>Amount</th>
<th>Penalty</th>
<th>Total Dues</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php

while ($result = mysqli_fetch_assoc($data))
{

echo "
      <tr style='text-align: center;'>                      
  <td style='display: none;'>".$result ['did']."</td>                                        
      <td>".$result ['year']."</td>                                      
      <td>".$result['amount']."</td>                                         
      <td>".$result['penalty']."</td>                                        
      <td>".$result['total']."</td>                                      
      <td>".$result['dstatus']."</td>                                    
      </tr>";                                       
  }
 }
else
{
  echo "<div style='color:red;'>No Records</div>";
}
?>
</tbody>            
</table>


<!-- TablEdit Script -->

<script>  
$(document).ready(function(){  
$('#paid_table').Tabledit({
      url:'duesaction.php',
      columns:{
      identifier:[0, "did"],
      editable:[
     [1, 'year'], 
     [2, 'amount'], 
     [3, 'penalty'], 
     [4, 'total'], 
     [5, 'status', '{"Paid": "Paid", "Unpaid": "Unpaid"}']
     ]
      },
      restoreButton:false,
      onSuccess:function(data, textStatus, jqXHR)
      {
       if(data.action == 'delete')
       {
        $('#'+data.did).remove();
       }
      }
     });
});
$(document).ready(function(){ 
$('#unpaid_table').Tabledit({
      url:'duesaction.php',
      columns:{
      identifier:[0, "did"],
      editable:[
      [1, 'year'], 
      [2, 'amount'], 
      [3, 'penalty'], 
      [4, 'total'], 
      [5, 'status', '{"Paid": "Paid", "Unpaid": "Unpaid"}']
      ]
     },
     restoreButton:false,
     onSuccess:function(data, textStatus, jqXHR)
     {
      if(data.action == 'delete')
      {
       $('#'+data.did).remove();
      }
     }
    });

});

</script>

当两个表都有数据时工作得很好,但如果任何表都没有数据则不起作用。我希望它在这两种情况下都有效。

请帮忙。

标签: phpjquerytabledit

解决方案


推荐阅读