Php 按行编辑表格
我有一个包含从SQL表检索的数据的表。我在每一行的末尾都附加了一个编辑按钮。编辑按钮允许用户编辑特定项目的信息。我想编辑按钮,让用户的信息是附加到。例如:Php 按行编辑表格,php,mysql,html-table,edit,Php,Mysql,Html Table,Edit,我有一个包含从SQL表检索的数据的表。我在每一行的末尾都附加了一个编辑按钮。编辑按钮允许用户编辑特定项目的信息。我想编辑按钮,让用户的信息是附加到。例如: -------------------------- NAME | AGE | GENDER | -------------------------- A | 4 | Female |EDIT -------------------------- B | 9 | Female |EDIT -----------------
--------------------------
NAME | AGE | GENDER |
--------------------------
A | 4 | Female |EDIT
--------------------------
B | 9 | Female |EDIT
--------------------------
C | 2 | Male |EDIT
--------------------------
如果我单击A行上的编辑按钮,它将允许我编辑A的信息。
请帮忙
<form id="edit" name="edit" method="post" action="edititem.php">
<table width="792" border='1' align='center' cellpadding='0' cellspacing='0' id='usertable'>
<tr bgcolor=#706C4B style='color:black'>
<td width="16%" align='center' id="box_header2" style='width:10%'>Item Name</td>
<td width="16%" align='center' id="box_header2" style='width:10%'>Item Quantity</td>
<td width="14%" align='center' id="box_header2" style='width:13%'>Storage Capacity</td>
<td width="13%" align='center' id="box_header2" style='width:11%'>Brand</td>
<td width="13%" align='center' id="box_header2" style='width:11%'>Color</td>
<td width="13%" align='center' id="box_header2" style='width:12%'>MAC Address</td>
<td width="13%" align='center' id="box_header2" style='width:12%'>S/N Number</td>
<td width="13%" align='center' id="box_header2" style='width:12%'></td>
</tr>
<?php
$sql="select * from item";
$result=mysql_query($sql);
while ($row=mysql_fetch_array($result))
{
?>
<tr bgcolor=#cfccb7 style='color:black'>
<td><div align="center"><?php echo $row['item_name']?></div></td>
<td><div align="center"><?php echo $row['item_quantity']?></div></td>
<td><div align="center"><?php echo $row['item_capacity']?></div></td>
<td><div align="center"><?php echo $row['item_brand']?></div></td>
<td><div align="center"><?php echo $row['item_color']?></div></td>
<td><div align="center"><?php echo $row['item_mac']?></div></td>
<td><div align="center"><?php echo $row['item_sn']?></div></td>
<td><div align="center"><input type="submit" name="button" id="button" value="Edit" /></div></td>
</tr>
<?php
}
?>
</table>
</form>
项目名称
项目数量
存储容量
烙印
颜色
MAC地址
序列号
这是一个部分答案,可能会让您开始学习。
当用户单击按钮时,您需要执行如下SQL语句:
//定义更新查询$SQLQuery=” 更新您的表名
设置column1='“$phpVariable1.”,
第2列=“$phpVariable2.”,
其中keyCol=“$phpVariableKey.”
//运行更新查询
$result=mysql\u查询($SQLQuery)
$phpVariableKey在您的情况下包含值“A”。理论上,您希望为每一行的按钮提供一个与数据库中该行相关的唯一值(即按钮1、按钮2等)。然后,您可以根据submit按钮的值接受并处理表单输入。例如,可以基于按钮值显示编辑屏幕,或者显示可编辑文本字段,而不是表中该行的内容
或者,您可以通过JavaScript将单击处理程序附加到按钮,该JavaScript使用特定行的可编辑文本
input
字段替换表格单元格的内容。处理表单的帖子时,您可以根据这些新文本字段的值更新数据库。您希望如何编辑它?通过表格提交。。。页面上的Javascript编辑?这还不清楚。