Question: I have written a php code to display data as a table, using the values come from a MySQL database. I am adding 2 buttons to end of each row, 'Approve' and 'Reject' for example. It's something like this:

```
<?php
$con2=mysqli_connect ("localhost","root","","leavemanagement");
$res=mysqli_query($con2,"SELECT c.* , p.* FROM leaveapplication c,emp p WHERE c.empno=p.empno");
while($row=mysqli_fetch_array($res))
{
?>
<tr>
<td><p><?php echo $row['empno']; ?></p></td>
<td><p><?php echo $row['name']; ?></p></td>
<td><p><?php echo $row['dept']; ?></p></td>
<td><p><?php echo $row['startdate']; ?></p></td>
<td><p><?php echo $row['enddate']; ?></p></td>
<td><p><?php echo "<input type='submit' name='action' value='Approve' /><input type='submit' name='action' value='Reject' />" ?></p></td>
</tr>
<?php
}
?>

```

How can I perform an action based on each button click? For example if the user clicks 'Approve' button on 4th row, it should pick 'empno', 'startdate', 'enddate' of that row, so I can pass that data to update the database.

Answer: 
Easiest way would be to transform each `<tr>` block into a form. 

Example: 

```
...
<tr>
   <form ...>
      <td><p><?php echo $row['empno']; ?></p></td>
      <td><p><?php echo $row['name']; ?></p></td>
      <td><p><?php echo $row['dept']; ?></p></td>
      <td><p><?php echo $row['startdate']; ?></p></td>
      <td><p><?php echo $row['enddate']; ?></p></td>
      <td><p><?php echo "<input type='submit' name='action' value='Approve' /><input type='submit' name='action' value='Reject' />" ?></p></td>
   </form>
</tr> 
...

```

Edit: For tracking you can use another `<input type="hidden" value="...">` field with a relevant value for that row
You're being shown an unnecessary use of forms. Make the TR have an ID equal to the row number. Then use an AJAX request using the row number and button pressed (accept or reject) to make the desired change. I'm on my phone now but I can add an example of this later if you'd like.