php - 在 php 中为 html 表上的行添加删除按钮

标签 php html mysql

我试图让它有一个可以按下的删除按钮,它会删除您按下删除按钮的列。我进行了广泛的研究,但似乎无法弄清楚。

这是 PHP 和 HTML:

<?php


$username="xxx";
$password="xxx";
$database="xxx";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");


$query="SELECT * FROM reservation__date ORDER BY reservation_date DESC";
$result = mysql_query ($query) or die(mysql_error());

$num=mysql_numrows($result);
mysql_close();
?>
            <table width="700" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC" id="myTable" class="tablesorter">
  <thead> 
        <tr valign="bottom" bgcolor="#000000">
          <th width="128"><span class="style1b"><strong>Reservation&nbsp;ID</strong></span></th>
          <th width="829" bgcolor="#2E64FE"><span class="style1b"><strong>Reservation&nbsp;Date</strong></span></th>
          <th width="829"><span class="style1b"></span></th>
          <!--  <th width="90"><span class="style1b"><strong>Agent/client</strong></span></th>-->
          </tr>
        </thead> 
<?php

$i=0;
while ($i < $num) {

$f1=mysql_result($result,$i,"reservation_id");
$f2=mysql_result($result,$i,"reservation_date");
?>

最佳答案

<?php    
$i=0;
while ($i < $num) {
    $f1=mysql_result($result,$i,"reservation_id");
    $f2=mysql_result($result,$i,"reservation_date");
?>
   <tr>
     <td><?echo $f1; ?></td>
     <td><?echo $f2; ?></td>
     <td><a href='delete.php?id=<?php echo $f1; ?>'>del</a></td>
   </tr>
<? } ?>

在 delete.php 中

$username="xxx";
$password="xxx";
$database="xxx";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "delete from reservation__date where reservation_id=$_GET[id]";
$rs = mysql_query ($query);
if($rs){
  header('Location: yourfile.php');
}

关于php - 在 php 中为 html 表上的行添加删除按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18272586/

相关文章:

javascript - 如何检测页面溢出

Javascript - 按类(class)获得跨度?

mysql - qt5.1.1 mysql ubuntu QMYSQL驱动未加载

php - 数组声明

php - 如何从 SQL 表计算高分?

php - Socialite laravel 5.4 Facebook登录报错(RequestException.php line 111中的ClientException)

javascript - 切换导航栏未正确切换

php - MySQL Import 通过 PhpMyAdmin 成功导入转储文件。但是通过PHP导入不行

php - 如何从本地网站在线访问mysql数据库?

php - MySQL 启动错误 - 缺少根元素