【问题标题】:How to get the ID of a row on a table如何获取表中一行的ID
【发布时间】:2016-05-15 00:28:22
【问题描述】:

我想获取表格上一行的 ID,以便一旦单击该行的删除按钮,该行将被删除。请帮忙。

$sql = "SELECT * FROM `users`";
$result = $conn->query($sql);

if($result !== false) {

echo "<form method='post' action=''>";
foreach($result as $row) {

  echo $row['id']. ' - '. $row['user_email']. ' - '. $row['user_password']. ' - '. $row['user_username'];

  echo "<button type='submit' class='btn btn-link'>Delete</button><br>";
 echo "</form>";


}

}

【问题讨论】:

  • 请您尝试过什么!
  • 在这里添加你的代码!!
  • 你的桌子怎么样?

  • ...在点击时使用 .delete-row。
  • 是否可以在脚本标签中调用php,以便我可以删除数据库中的行?

标签: javascript php pdo


【解决方案1】:
<table id="example">
    <thead>
    <tr>
        <th>name</th>
        <th>age</th>
        <th></th>
    </tr>
    </thead>
    <tbody>
    <tr id="row11">
        <td>murali</td>
        <td>25</td>
        <td><button>get data</button></td>
    </tr>
    <tr id="row12">
        <td>murali2</td>
        <td>24</td>
        <td><button>get data</button></td>
    </tr>
    </tbody>
</table>
<script src="js/jquery.min.js"></script>
<script>
    $('#example tbody').on('click', 'button', function () {
        var btn = $(this);
        if(btn){
            var row = $(this).closest('tr');
            console.log(row[0]);

        }
    })
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-15
    • 2012-06-27
    • 2017-11-02
    • 1970-01-01
    • 1970-01-01
    • 2020-09-15
    • 1970-01-01
    • 2017-10-13
    相关资源
    最近更新 更多