Q:

Sending Current Variable Value through a Link

I have a table that is generated from data inside of a database.
Each row of the table is one row of my database. At the end of each row I create a link to start the process of removing the data from the table and database. Here is a snip of my code:
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        echo "<tr>";
        echo "<th>".$row["username"]."</th>";
        $user = $row["username"];
        echo "<th>".$row["name"]."</th>";
        $name = $row["name"];
        echo "<th><a href='./test.php'.urlencode($user)>Remove</a></th>";
        echo "</tr>";
    }
}

As you can see, once the link is clicked I want to run test.php with the variable (and its value for that row) already set. Ive attempted to do this with urlencode but when doing a echo $user, it returns as undefined variable. I have also tried echo "<th><a href='./test.php?link='$user>Remove</a></th>";.
I would like to be able to send up to 6 variables with values.
EDIT 1:
Here is a picture of one row from my table:

The first two columns are username and name. You can see that the values are set and displayed within the while loop. I would like each iteration of the loop to create a unique link to remove that row from the database. Or simply for this case, send the data values for that row when the link is clicked.

A:

You can use http_build_query function:
$qs = [
    'user' => $row["username"],
    'name' => $row["name"],
    // ... 4 more values
];
echo '<th><a href="test.php?' . http_build_query($qs, null, '&amp;', PHP_QUERY_RFC3986) . '">Remove</a></th>';

