Advertisement
Guest User

Untitled

a guest
Mar 9th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "";
  6. $dbname = "akademik";
  7.  
  8. // Create connection
  9. $koneksi = mysqli_connect($servername, $username, $password, $dbname);
  10. // Check connection
  11. if (!$koneksi) {
  12. die("Connection failed: " . mysqli_connect_error($koneksi));
  13. }
  14.  
  15. $sql = "SELECT * FROM mahasiswa";
  16. $result = mysqli_query($koneksi, $sql) or die (mysqli_error($result));
  17. echo '<table border="5">';
  18. echo '<tr bgcolor="#006600">';
  19. echo '<td>Nim</td>';
  20. echo '<td>Nama</td>';
  21. echo '<td>Umur</td>';
  22. echo '<td>Gender</td>';
  23. echo '</tr>';
  24. if (mysqli_num_rows($result) > 0) {
  25. // output data of each row
  26. while($row = mysqli_fetch_array($result)) {
  27. echo "<tr>";
  28. echo "<td>$row[0]</td>";
  29. echo "<td>$row[1]</td>";
  30. echo "<td>$row[2]</td>";
  31. echo "<td>$row[3]</td>";
  32.  
  33. echo "</tr>";
  34.  
  35.  
  36. }
  37. mysqli_free_result($result);
  38. } else {
  39. echo "0 results".mysqli_error($result);
  40. }
  41.  
  42. //mysqli_close($koneksi);
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement