Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.89 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "";
  5. $dbname = "test";
  6.  
  7. // Create connection
  8. $conn = new mysqli($servername, $username, $password, $dbname);
  9. // Check connection
  10. if ($conn->connect_error) {
  11.     die("Connection failed: " . $conn->connect_error);
  12. }
  13.  
  14. //nome do db é test e da tabela é teste
  15. $sql = "SELECT id, teste1, teste2,teste3 FROM teste";
  16. $result = $conn->query($sql);
  17.  
  18. if ($result->num_rows > 0) {
  19.     echo "<table><tr><th>ID</th><th>teste1</th><th>teste2</th><th>teste3</th></tr>";
  20.     // output data of each row
  21.     while($row = $result->fetch_assoc()) {
  22.         echo "<tr>";
  23.         echo "<td>".$row["id"]."</td>";
  24.         echo "<td>".$row["teste1"]. "</td>";
  25.         echo "<td>".$row["teste2"]. "</td>";
  26.         echo "<td>".$row["teste3"]. "</td></tr>";
  27.     }
  28.     echo "</table>";
  29. } else {
  30.     echo "0 results";
  31. }
  32. $conn->close();
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement