我有一个显示数据库中所有条目的 html 表,因此每个条目都有一行。
我也有每一行的按钮。
当我单击按钮时,我想编辑与按下的按钮关联的行的值,并获取与该特定行相关的所有值。
<html>
<body>
<?php
$user="user";
$password="password";
$database="database";
$username=$_SESSION['username'];
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM table";
$result=mysql_query($query);
$num=mysql_numrows($result);
?>
<form id="view_admin" method="post">
<table id="my_table" class= "sample" >
<tr>
<td align="center"><strong><font face="Arial, Helvetica, sans-serif">Id</font></strong></td>
<td align="center"><strong><font face="Arial, Helvetica, sans-serif">Column1</font></strong></td>
<td align="center"><strong><font face="Arial, Helvetica, sans-serif">Status</font></td>
<td align="center"><strong><font face="Arial, Helvetica, sans-serif">Edit Status</font></td>
</tr>
<?php
$i=0;
while ($i < $num) {
$f0=mysql_result($result,$i,"id");
$f1=mysql_result($result,$i,"column1");
$f2=mysql_result($result,$i,"status");
?>
<tr>
<td align="center"><font face="Arial, Helvetica, sans-serif"><?php echo $f0; ?></font></td>
<td align="center"><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>
<td align="center"><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td>
<td align="center"><input type="submit" name="approved" value="approve"> <input type="submit" name="refused" value="refuse"> </td>
</tr>
<?php
if (isset($_POST['approved'])) {
$query_update = "UPDATE main SET status='APPROVED' WHERE id ='$f0'";
$result_update=mysql_query($query_update);}
else if (isset($_POST['refused'])) {
$query_update = "UPDATE main SET status='REFUSED' WHERE id ='$f0'";
$result_update=mysql_query($query_update);
}
$i++;
}
mysql_close();
?>
</table>
</form>
</body>
</html>
现在,当我按下按钮时,所有行都会更新。
我该如何解决我的问题?