简体   繁体   中英

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. I've managed to populate an html table with a mySql database. 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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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