Reputation: 450
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>";
}
Upvotes: 1
Views: 111
Reputation: 302
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.
Upvotes: 1
Reputation: 336
One way to do it is to have a "click event" attached to the button with the ID of that row passed to the event, so any time the button is clicked, you know which row it was based on the ID.
Upvotes: 1