Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require'config.php';
- ?>
- <html>
- <head>
- <meta charset="UTF-8">
- <title></title>
- </head>
- <body>
- <form method="GET">
- Liste por: <select name="ordem" onchange="this.form.submit()">
- <option></option>
- <option value="nome">Pelo Nome</option>
- <option value="idade">Pela Idade</option>
- </select>
- </form>
- <a href="adicionar.php">Adicionar Usuario</a>
- </br></br>
- <table width="500" border="1">
- <tr>
- <th>Id</th>
- <th>Nome</th>
- <th>Email</th>
- <th>Idade</th>
- <th>Ações</th>
- </tr>
- <?php
- if (isset($_GET['ordem']) && empty($_GET['ordem'])== false) {
- $ordem = addslashes($_GET['ordem']);
- $sql = "SELECT * FROM usuarios ORDER BY".$ordem;
- }else{
- $sql= "SELECT * FROM usuarios";
- }
- $sql = $pdo->query($sql);
- if ($sql->rowCount() > 0) {
- foreach ($sql->fetchAll() as $usuario){
- echo '<tr>';
- echo '<td>'.$usuario['id']."</td>";
- echo '<td>'.$usuario['nome']."</td>";
- echo '<td>'.$usuario['email']."</td>";
- echo '<td>'.$usuario['idade']."</td>";
- echo '<td><a href="editar.php?id='.$usuario['id'].'">Editar</a> - <a href="excluir.php?id='.$usuario['id'].'"> Excluir</a></td>';
- echo '</tr>';
- }
- }else{
- echo"Erro a selecionar usuario";
- }
- ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement