简体   繁体   English

PHP-如何在html表中编辑特定行并更新数据库?

[英]Php - How can I edit a certain row in my html table and update my db?

I'm fairly new to php and I know the question has been asked a lot, but please bear with me. 我对php很陌生,我知道这个问题已经问了很多,但是请忍受。 I've managed to populate an html table with a mySql database. 我设法用mySql数据库填充html表。 At the end of each row is a check in button that resets the date on the row. 每行末尾都有一个签入按钮,用于重置行中的日期。 My question is how, can I keep track of which row the button belongs too so I know to only update that row? 我的问题是,如何也可以跟踪按钮属于哪一行,以便知道仅更新该行?

I have an ID on each row so I know I can use that when updating to the table, but I'm just uncertain how to associate each button to it's respective row. 我在每行上都有一个ID,所以我知道在更新到表时可以使用该ID,但是我不确定如何将每个按钮关联到其相应的行。 Here's a snippet: 这是一个片段:

while ($row = mysql_fetch_array($result)) {
    echo "<tr>";
    echo "<td class='text-left'>".$row[card_id]</td>";
    echo "<td class='text-left'>".$row[status]</td>";
    //current student
    echo "<td class='text-left'>".$row[user_id]."</td>";
    echo "<td class='text-left'>".$row[end_date]."</td>";

    //Early Check In button
    echo "<td class='text-left'><button class='checkInBtn'></button></td>";
    echo "</tr>";
}

一种实现方法是在按钮上附加一个“单击事件”,并将该行的ID传递给事件,因此,每当单击该按钮时,您就知道它是基于ID的。

You can send the id to a js function using click event. 您可以使用click事件将ID发送给js函数。 You can also create a form, inside the form you can create an input hidden and assign it the value, and you can use this value when user submit the buttom. 您还可以创建一个表单,在表单内部可以创建隐藏的输入并为其指定值,并且在用户提交按钮时可以使用此值。

With this id you can modify the info, and create other view to modify it. 使用此ID,您可以修改信息,并创建其他视图进行修改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM