1

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>";
}
5
  • your html is broken. you are outputting MULTIPLE id=checkInBtn, which is illegal. an id MUST be unique across the ENTIRE document. Commented Oct 11, 2016 at 18:47
  • the php also has errors. if you can clean up your code it would get you better answers. Commented Oct 11, 2016 at 18:49
  • 1
    Please stop using mysql_* functions. These extensions have been removed in PHP 7. Learn about prepared statements for PDO and MySQLi and consider using PDO, it's really pretty easy. Commented Oct 11, 2016 at 18:51
  • Which php errors do you mean? Commented Oct 11, 2016 at 19:01
  • Can you be more specific in your question that we can help you.. Commented Oct 11, 2016 at 19:02

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

I see. Could you show me a small example of how that would look? something like <button onclick="checkInFunction(<?php echo $id?>))">Click me</button> ?
You can send data in url and receive data with get. Example: <a href="delete.php?id=<?php echo $r->id; ?>">Delete</a> In your delete.php you can receive it like this: <?php $id = $_GET['id']; echo "id : ".$identificador;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.