我的网站将从 MySQL 数据库创建一个表。我想知道他们是否是一种在每一行旁边都有一个删除按钮的方法,以便成员可以删除他们表上的特定行。其他一切正常。我希望用户能够从他们的表中删除他们的行。
<form action="addcel.php" method="post">
Name <input type="text" name="Name"/>
Year <input type="text" name="year"/>
<input type="submit" />
<html><head><title>MySQL Table Viewer</title></head><body>
<?php
echo "<style type = 'text/css'>
table {width:700px;border:none;text-align:center;background-color:#B0B0B0;font-family:'Arial';}
#tabledata {padding:2px;border-width:0px;}
#tableheader {border-width:0px;}
#line {border:1px solid black;padding:0px;}
</style>";
$db_host = 'localhost';
$db_user = 'root';
$db_pwd = '';
$database = 'Name_gage';
$table = 'Name';
if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");
if (!mysql_select_db($database))
die("Can't select database");
// sending query
$result = mysql_query("SELECT * FROM {$table}");
if (!$result) {
die("Query to show fields from table failed");
}
$fields_num = mysql_num_fields($result);
echo "<h1>Table: {$table}</h1>";
echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
$field = mysql_fetch_field($result);
echo "<th id = 'tableheader'>{$field->name}</th>";
}
echo "</tr>\n";
echo "<tr><td id = 'line'></td id = 'line'><td id = 'line' ></td><td id = 'line' ></td><td id = 'line' ></td><td id = 'line' ></td></tr>";
// printing table rows
while($row = mysql_fetch_row($result))
{
echo "<tr>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td id = 'tabledata'>$cell</td>";
echo "</tr>\n";
}
mysql_free_result($result);
?>
</body></html>