i have the same problem as yours and tried to create an answer so i came up with this code to indicate each row in an HTML table with a special name using loops, i can now take the specified row and do as much PHP operations as i can with it without disturbing the table as a whole and it was well synchronized with my database, hope it helps! 
and btw the whole "marking each row with a special name" code is in usersTable.php
users.sql
create table users(
    id int,
    username varchar(50),
    password varchar(50)
);
users.php
<?php
$host = "localhost";
$username = "root";
$password = "";
$database = "wdl2hw4db";
$conn = mysqli_connect($host, $username, $password, $database);
if (mysqli_connect_errno()){
    die("can't connect to the Database" . mysqli_connect_errno());
}else{
    echo "Database is connected" . "<br>";
}
if (isset($_POST['insert'])){
    $idN1= $_POST['id'];
    $usernameN1 = $_POST['username'];
    $passwordN1 = $_POST['password'];
    $query = "insert into users(id, username, pass) values ('".$idN1."' , '".$usernameN1."' , '".$passwordN1."' )";
    $result = mysqli_query($conn, $query);
}else if (isset($_POST['update'])){
    $idN2 = $_POST['id'];
    $usernameN2 = $_POST['username'];
    $passwordN2 = $_POST['password'];
    $query = "update users set pass = '". $passwordN2 ."'where id = " . $idN2;
    $result = mysqli_query($conn, $query);
}else if (isset($_POST['Display'])){
    header('Location: usersTable.php');
}
echo "<br>";
?>
<form method="post">
    ID: <input type="text" name="id" ><br><br>
    username: <input type="text" name="username" ><br><br>
    password: <input type="password" name="password" ><br><br>
    <input type="submit" name="insert" value="insert">
    <input type="submit" name="Display" value="Display">
</form>
userTable.php
<?php
$host = "localhost";
$username = "root";
$password = "";
$database = "wdl2hw4db";
$conn = mysqli_connect($host, $username, $password, $database);
$query = "select * from users";
$result = mysqli_query($conn, $query);
echo "<table border=\"6px\"><thead><tr><th>ID</th><th>username</th><th>password</th><th>Delete</th><th>Update</th></tr></thead>";
$i = 1;
while ($row = mysqli_fetch_assoc($result)) {
    echo "<tr><form method='post'><td>" . $row['id'] . "</td><td>" . $row['username'] . "</td><td>" . $row['pass'] . "</td><td><input type='submit' name='Delete" . $i . "' value='Delete'></td><td><input type='submit' name='Update" . $i . "' value='Update'><input type='text' name='UpdateText" . $i . "' placeholder='insert new password here'></td></form></tr>";
    $i++;
}
echo "</table>";
$i = 1;
$result2 = mysqli_query($conn, $query);
while ($row2 = mysqli_fetch_assoc($result2)) {
    if (isset($_POST['Delete' . $i])) {
        $usernameN4 = $row2['username'];
        $query2 = "delete from users where username ='" . $usernameN4 . "'";
        $result2 = mysqli_query($conn, $query2);
        header("Refresh:0");
        break;
    }
    $i++;
};
$i = 1;
$result3 = mysqli_query($conn, $query);
while ($row3 = mysqli_fetch_assoc($result3)) {
    if (isset($_POST['Update' . $i]) && $_POST['UpdateText' . $i] != null ) {
        $id4 = $row3['id'];
        $Utext = $_POST['UpdateText' . $i];
        $query3 = "update users set pass ='" . $Utext . "' where id = " . $id4;
        $result3 = mysqli_query($conn, $query3);
        header("Refresh:0");
        break;
    }
    $i++;
};
mysqli_free_result($result);