首页 > 解决方案 > 将删除按钮添加到表类

问题描述

我想在每一行的表格中添加一个删除按钮,以便能够删除 ro 。

这就是我设置表的方式:

<table class="CustomClass" border="2" style= "background-color: #f9f9f9; color: #000000; margin: 0 auto;" >
      <thead style= "background-color: #FFFFFF">
        <tr>
          <th>ID</th>
          <th>Name</th>
          <th>Date</th>
          <th>Tag</th>
        </tr>
      </thead>
      <tbody>
        <?php
          if ($result = $mysqli->query($query)) {
              while ($row = $result->fetch_assoc()) {
                  echo
                  "<tr>
                  <td>{$row['id']}</td>
                  <td>{$row['namec']}</td>
                  <td>{$row['datec']}</td>
                  <td>{$row['tagc']}</td>
                  </tr>\n";
                  
              }
              $result->free();
          }
        ?>
      </tbody>
    </table>

我已经尝试过这样的事情,但看起来并不正确:

<td>
      <input type="button" value="Delete Row" onclick="SomeDeleteRowFunction(this);">
    </td>

这里有什么解决方案吗?

标签: phphtml

解决方案


好的,在你的头上添加这个在另一个标签之上

<th>Delete</>

并在你的 tbody 上面添加你的 td 标签:

<td><a href="/traitement.php?sup='.$yourindex->id.'"><i "crossiconwhaterveryoulike"></i></a> </td>

然后在 traitement.php 添加:

    if(isset($_GET['sup']))
{
    $id=$_GET['sup'];
    del_membreData($id);

    header("location:youinitialpage.php");
}

其中 del_membreData($id) 是函数:

function del_membreData($idUser)
{
    $dbh=connexion();
    $sql= "DELETE FROM yourtable WHERE id=:id"; /*put the name of your table */
    $sth=$dbh->prepare($sql);
    $sth->bindParam(":id", $id, PDO::PARAM_INT);
    $sth->execute() or die (print_r($sth->errorInfo(), true));
    $sth->closeCursor();
}

我不知道你的每一个变量,但它可能会起作用。当然你必须改变一些,仔细阅读代码


推荐阅读