如何提取数据表中所选行的第一列



我想在单击时提取数据表的第一列。

这是我的数据表代码,来源于我的 SQL 数据库

<tbody>
  <form action="index.php   " method="POST">
    <?php
      while($row = mysqli_fetch_array($showMemo))
      {
          echo'
            <tr>
                <td>'. $row["employee_id"]     .'</td>
                <td>'. $row["employee_name"]   .'</td>
                <td>'. $row["employee_number"] .'</td>
                <td>'. $row["employee_status"] .'</td>
                <td>'. 
                   <a href="..." id="edit" >Activate Employee</a> .' 
                </td>
            </tr>
              ';
      }
    ?>
  </form>

让我们分解一下:
员工 ID:我的"员工"表中的主键
员工姓名:员工姓名员工人数
:员工人数
员工状态:[活动] 或 [非活动]
激活员工链接: [1] 用于激活员工 [0] 停用员工



我很难添加获取第一列 (employee_id(,该列将被引用用于更新的行。

这是我的jQuery

<script>
    $(document).ready( function () {
        $('#myTable').DataTable({
                "order": [[ 6, 'asc' ]]});
    } );
</script>

提前谢谢。

您可以通过引用获得它。

首先,您不应该在循环中定义固定 id(它们应该是唯一的(:

更改此设置:

<a href="..." id="edit" >Activate Employee</a> .' 

对此:

 <a href="..." class="edit" >Activate Employee</a> .' 

然后这应该会得到你的id:

$('.edit').click(function(ev) {
   ev.preventDefault(); // Avoid the href to be followed by the browser
   // get the contents of the first td in the closest tr 
   var id = $('td:first-child', $(this).closest('tr')).html();
   // Just continue with your ajax request...
});

最新更新