# http://localhost:8080/aula4/pessoas/listar.php
// o objetivo da página é apresentar a tabela pessoas
require_once("../connection.php");
$tabela="v1_pessoas";
$sql="SELECT * FROM $tabela";
$query=mysqli_query($connect, $sql) or die(header("Location:../erros.php?erro=4"));
$total=mysqli_num_rows($query);
if($total>0){
$fetch=mysqli_fetch_assoc($query);
}
?>
<!DOCTYPE html>
<html lang="pt">
<head>
<meta charset="UTF-8">
<title>Listar pessoas</title>
</head>
<body>
<a href="criar.php">Registar nova pessoa</a>
<?php if($total>0){ ?>
<p>Foram encontrados <span><?php echo $total; ?></span> registos.</p>
<div>
<table border="1" cellpadding="10">
<tr><!-- cabeçalho -->
<th>Nome</th>
<th>Apelido</th>
<th>Estado</th>
<th>Editar</th>
<th>Apagar</th>
</tr>
<?php do { ?>
<tr>
<td><?php echo $fetch['nome'];?></td>
<td><?php echo $fetch['apelido'];?></td>
<td><a href="alterarEstado.php?alterar&id=<?php echo $fetch['id'];?>&estado=<?php echo $fetch['estado'];?>"><?php echo $fetch['estadoTxt'];?></a></td>
<td><a href="alterarDados.php?filtrar&id=<?php echo $fetch['id'];?>">Alterar</a></td>
<td><a href="apagarPessoas.php?apagar&id=<?php echo $fetch['id'];?>" onclick="return confirm('Tem a certeza que pretende apagar o registo de <?php echo $fetch['nome'].' '.$fetch['apelido'];?>')">Apagar</a></td>
</tr>
<?php } while($fetch=mysqli_fetch_assoc($query));?>
</table>
</div>
<?php } ?>
<?php if($total==0){ ?>
<p>Não foram encontrados registos.</p>
<?php } ?>
</body>
</html>
Sem comentários:
Enviar um comentário