Advertisement
craftyoyo

mail

Aug 18th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1. <?php
  2. $con=mysqli_connect("example.com","peter","abc123","my_db");
  3. // Check connection
  4. if (mysqli_connect_errno())
  5. {
  6. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  7. }
  8.  
  9. $result = mysqli_query($con,"SELECT * FROM Persons");
  10.  
  11. echo "<table border='1'>";
  12.  
  13. $i = 0;
  14. while($row = $result->fetch_assoc())
  15. {
  16.     if ($i == 0) {
  17.       $i++;
  18.       echo "<tr>";
  19.       foreach ($row as $key => $value) {
  20.         echo "<th>" . $key . "</th>";
  21.       }
  22.       echo "</tr>";
  23.     }
  24.     echo "<tr>";
  25.     foreach ($row as $value) {
  26.       echo "<td>" . $value . "</td>";
  27.     }
  28.     echo "</tr>";
  29. }
  30. echo "</table>";
  31.  
  32. mysqli_close($con);
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement