duanjia4097 2013-04-20 01:38
浏览 64

将编辑按钮添加到html表中的每一行,以编辑数据库

I am relatively new to php, and need help with a program i am doing for an internship... on the page i am trying to create, i queried all records in the mysql database, and inserted them into an html table. What i am trying to do, is also add an edit button in a separate column of each row of the table, so the rows can be edited.. i know how to get the button there, but i do not know how i can get the values out of that particular row, into a php variable so i can perform more queries to edit, delete, etc... I have been looking for a couple days, and it looks like it may be possible to do with javascript, but i have never used javascript before, so i do not know what im looking at... help would be much appreciated

basically:

<html>
<table border="1">

<th>Suspended</th>
<th>Device Name</th>
<th>IP</th>
<th>Depend</th>
<th>Email</th>

<?php
$sql = "select * from table;"

while($row=mysql_fetch_assoc($sql))
{
echo "<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td><td>".$row[3]."       </td><td>".$row[4]."</td></tr>";
}
?>

</table>
</html>

==I have not really tried anything yet for the edit/delete buttons.. i dont really know where to start

  • 写回答

1条回答 默认 最新

  • douhuan4699 2013-04-20 01:54
    关注

    For each of the edit buttons create a form with a hidden field that stores a uniquely identifiable id for that row (a primary key value).

    <form action="editPage.php" method="post/get">
    <input type="hidden" name="id" value="<?php echo $row_id; ?>" />
    <input type="submit" value="Edit"/>
    </form>
    

    Then use the id to update the fields for that record in the database.

    What is $row_id? and how to use $rowvalue if i want to insert it to variable or session?

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog