Advertisement
Willian_vinicius

Untitled

Feb 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. <?php
  2. require'config.php';
  3. ?>
  4. <html>
  5. <head>
  6. <meta charset="UTF-8">
  7. <title></title>
  8. </head>
  9. <body>
  10.  
  11. <form method="GET">
  12. Liste por: <select name="ordem" onchange="this.form.submit()">
  13. <option></option>
  14. <option value="nome">Pelo Nome</option>
  15. <option value="idade">Pela Idade</option>
  16. </select>
  17. </form>
  18. <a href="adicionar.php">Adicionar Usuario</a>
  19. </br></br>
  20.  
  21. <table width="500" border="1">
  22. <tr>
  23. <th>Id</th>
  24. <th>Nome</th>
  25. <th>Email</th>
  26. <th>Idade</th>
  27. <th>Ações</th>
  28. </tr>
  29. <?php
  30. if (isset($_GET['ordem']) && empty($_GET['ordem'])== false) {
  31. $ordem = addslashes($_GET['ordem']);
  32. $sql = "SELECT * FROM usuarios ORDER BY".$ordem;
  33.  
  34. }else{
  35. $sql= "SELECT * FROM usuarios";
  36. }
  37.  
  38.  
  39. $sql = $pdo->query($sql);
  40. if ($sql->rowCount() > 0) {
  41. foreach ($sql->fetchAll() as $usuario){
  42. echo '<tr>';
  43. echo '<td>'.$usuario['id']."</td>";
  44. echo '<td>'.$usuario['nome']."</td>";
  45. echo '<td>'.$usuario['email']."</td>";
  46. echo '<td>'.$usuario['idade']."</td>";
  47. echo '<td><a href="editar.php?id='.$usuario['id'].'">Editar</a> - <a href="excluir.php?id='.$usuario['id'].'"> Excluir</a></td>';
  48. echo '</tr>';
  49.  
  50. }
  51.  
  52.  
  53. }else{
  54. echo"Erro a selecionar usuario";
  55. }
  56.  
  57. ?>
  58. </table>
  59. </body>
  60. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement