-1
Good evening guys, I’m developing a course completion work code and I have a question. I have a table users and vehicles, use Inner Join in select and then display them using foreach. However, in each field the user can choose or change the user or delete it (send the data according to the id selected using SESSION). But here’s the problem! When I try to pass the id code I want to modify, it just takes the last id instead of the respective code. For example: I want to delete code 1, hit delete, the system deletes code 3 instead of 1.
How my display is:
<table class="table">
<tr>
<th>Código</th>
<th>Nome</th>
<th>Telefone</th>
<th>Tipo</th>
<th>Placa</th>
<th>Modelo</th>
<th>Cor</th>
<th>Fabricante</th>
</tr>
<?php foreach ($dados as $linha):
$id = $linha[0];
?>
<tr>
<td><?php echo $linha[0]; ?></td>
<td><?php echo $linha[1]; ?></td>
<td><?php echo $linha[2]; ?></td>
<td><?php echo $linha[3]; ?></td>
<td><?php echo $linha[4]; ?></td>
<td><?php echo $linha[5]; ?></td>
<td><?php echo $linha[6]; ?></td>
<td><?php echo $linha[7]; ?></td>
<td><a name="altera" onclick="
<?php
$_SESSION['id'] = $id;
$_SESSION['alterar'] = 'usuario';
?>" href="alterar.php">Alterar</a></td>
<td><a name="excluir" onclick="
<?php
$_SESSION['excluir'] = 'usuario';
?>" href="processaexcluir.php">Excluir</a></td>
</tr>
<?php
}
$id++;
endforeach;
?>
</table>
I wonder if there is any way to search for a specific index in the foreach or if there is some other way to do it. Thank you for your attention.
try to use just one, so: <td><? php echo $line; ? ></td> delete the others, no need to loop.
– Macedo_Montalvão