I have a table in my database known as adminapprove which has various fields. I use php to select all the data and display it inside a table.
I want one of the columns to have 2 buttons (approve and deny). I used a form for this based on https://stackoverflow.com/a/40958782/10217754
// $data contains the result of sql query (select *)
while($row = $data->fetch_assoc())
{
 echo "
 // Each row has multiple fields along with this
 <tr><td>
  <form method=\"post\">
   <input type=\"submit\" value=\"approve\">
   <input type=\"submit\" value=\"deny\">
  </form>
 </td></tr>";
 if($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['approve']))  {
   approve($conn, $row);
   unset($_POST['approve']);
 }
 if($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['deny'])) {
   deny($conn, $row);
   unset($_POST['deny']);
 }
// code for closing table tag echo </table>
}
This is the php script after the form (inside the while loop)
- What I am aiming for is that whenever deny/approve is selected for some particular row, only that data(row) should be changed based on the option selected. 
- What is happening currently is that no matter whichever row I select, the last row in the table is changed based on the option selected. 
I am new to PHP and thought loops work similarly as they do in C++ - So I call functions inside the loop only and once the functions complete executing, I unset the variable so that the next row is unaffected. But this is clearly not the case(at least that's what I understood, Correct me if I am wrong). So what am I missing? How can I achieve this?
Thanks in Advance.
