Guest User

Untitled

a guest
Apr 28th, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>MySQLi example</title>
  4. <meta charset="utf8">
  5. </head>
  6.  
  7. <body>
  8.  
  9. <?php
  10. // Usaremos una base de datos (foobar) con una tabla (users) que contiene username y email.
  11.  
  12. $user = "root"
  13. $password = "mipasswordtopeguapens"
  14. $ddbb = "foobar"
  15.  
  16. $con = new mysqli("localhost", $user, $password, $ddbb);
  17.  
  18. // select a lo bestia porque yolo
  19. $sql_query= "select * from users";
  20.  
  21. // amoh ahí palante esa consulta
  22. $result = $con->query($sql_query);
  23.  
  24. // y ahora la sacamos por pantalla
  25. echo "<h1>Lista de usuarios</h1>";
  26. echo "<table>";
  27.  
  28. // la consulta devuelve un array asociativo, así que toca patearselo
  29. while($row = $result->fetch_assoc()) {
  30. echo "<tr><td>" . $row['username'] . "</td>" . "<td>" . $row['email'] . "</td></tr>";
  31. }
  32. echo "</table>";
  33. ?>
  34.  
  35. </body>
  36. </html>
Add Comment
Please, Sign In to add comment