php - 将删除按钮添加到表类
问题描述
我想在每一行的表格中添加一个删除按钮,以便能够删除 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>
这里有什么解决方案吗?
解决方案
好的,在你的头上添加这个在另一个标签之上
<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();
}
我不知道你的每一个变量,但它可能会起作用。当然你必须改变一些,仔细阅读代码
推荐阅读
- sql - 从查询中获取列名,单引号问题
- python - 文件创建者将文件夹名称识别为现有文件
- google-bigquery - 有没有办法增加 BigQuery 中查询的分配内存?
- angular - 效果只需在 Rxjs 6 中使用两个 Observable 调用一次
- r - 查找向量中的元素序列
- c - 在 C 中反转 2 的幂的最快方法是什么?
- swift - 如何根据信标的接近程度刷新背景图像?
- python-docx - 通过python在docx.zip的word文件夹中创建footer.xml文件,在word docx中创建页脚?
- ms-access - 用于添加新表行并分配主键的表单按钮
- rest - 进行查询 REST put 的问题,elasticsearch