You can create a stylized table with CSS. The result would be this:
Now to delete the record, I recommend deleting by the user id. To do so, also select the id (if the column name is id
) in consultation with the bank:
↓↓
"SELECT id, email, ddd, numero, FROM contas"
Codes:
CSS:
table{
width: 100%;
background-color: #ddd;
border-spacing: 1px;
}
th, td{
padding: 10px;
text-align: center;
}
table th{
background-color: #444;
color: #fff;
}
table td{
background-color: #fff;
}
table tfoot td{
background-color: #f5f5f5;
}
table tfoot td:first-child{
text-align: right;
}
HTML + PHP:
<?php
$servidor = "localhost";
$usuario = "root";
$senha = "";
$dbname = "id8146007_contasadm";
$conn = mysqli_connect ($servidor, $usuario, $senha, $dbname);
$db_select = mysqli_select_db ($conn ,$dbname);
$id = $_GET['id'];
if($_GET['acao'] == 'excluir' && !empty(id)){
// exclui o registro do banco
mysqli_query($conn, "DELETE FROM contas WHERE id = '$id'");
}
$query = sprintf ("SELECT id, email, ddd, numero, FROM contas");
$dados = mysqli_query ($conn,$query);
$linha = mysqli_fetch_assoc ($dados);
$total = mysqli_num_rows($dados);
?>
<table>
<tr>
<th>
<strong>E-mail</strong>
</th>
<th>
<strong>Número</strong>
</th>
<th>
</th>
</tr>
<?php while($linha){ ?>
<tr>
<td>
<?php echo $linha['email'] ?>
</td>
<td>
(<?php echo $linha['ddd'] ?>) <?php echo $linha['numero'] ?>
</td>
<td>
<button onclick='location.href = "?id=<?php echo $linha['id'] ?>&acao=excluir"'>Excluir</button>
</td>
</tr>
<?php } ?>
<tfoot>
<td colspan="2">
<strong>Total:</strong>
</td>
<td>
<?php echo $total ?>
</td>
</tfoot>
</table>