Always when you need to make a relationship, in the table that has the data that will relate to the user (in your case), must have a column identifying the user ID, so you can make the relationship. Then change the structure from tbl_comissao
to:
ID | id_usuario | comissao
1 | 1 | 13
2 | 2 | 26
To relate you can do 2 querys. One to pull the commissions and in the loop make another query to see which is the user of id_usuario
$result = mysqli_query($con,"SELECT id, comissao FROM tbl_comissao");
echo "<table border='1'>
<tr>
<th>Representante</th>
<th>Comissão</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
$usuarioQuery = mysqli_query($con,"SELECT nome FROM tbl_usuario WHERE id = '".$row['id_usuario']."' ");
$rowUser = mysqli_fetch_array($usuarioQuery);
$id = $row['id'];
$comissao = $row['comissao'];
echo "<tr>";
echo "<td>" . $rowUser[0]['nome'] ."</td>";
echo "<td>" . "R$ ".number_format($comissao,2, ',', '.') . "</td>";
echo "</tr>";
}
echo "</table>";
But the best solution is to use INNER JOIN
or LEFT JOIN
or RIGHT JOIN
(depends on your need) to make the relation:
$result = mysqli_query($con,"SELECT c.id, c.comissao, u.nome FROM tbl_comissao AS c INNER JOIN tbl_usuario AS u ON u.id = c.id_usuario");
echo "<table border='1'>
<tr>
<th>Representante</th>
<th>Comissão</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
$id = $row['id'];
$comissao = $row['comissao'];
echo "<tr>";
echo "<td>" . $row['nome'] ."</td>";
echo "<td>" . "R$ ".number_format($comissao,2, ',', '.') . "</td>";
echo "</tr>";
}
echo "</table>";
Read this topic to see how to use the JOIN clauses