Advertisement
Guest User

Kok gak muncul

a guest
Nov 15th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. //ini file koneksi.php
  2. <?php
  3. $host="localhost";
  4. $username="root";
  5. $password="";
  6. $db_name="oop";
  7.  
  8. mysql_connect($host,$username,$password,$db_name) or DIE("Koneksi ke DB gagal!");
  9. mysql_select_db($db_name)or DIE ("Nama DB tidak ada");
  10. ?>
  11.  
  12.  
  13. //ini file class.php
  14. <?php
  15. require 'koneksi.php';
  16. //Class Database
  17. class operasi{
  18.  
  19. function lihatdata(){
  20. $tampil=mysql_query("SELECT nim,thang,nama,alamat From mahasiswa;");
  21. while($row=mysql_fetch_array($tampil))
  22. $data[]=$row;
  23. return $data;
  24. }
  25.  
  26. }
  27.  
  28. ?>
  29.  
  30.  
  31.  
  32. //ini file yang manggil show.php
  33. <?php
  34. require_once 'classoperasi.php';
  35. $hasil=new operasi();
  36. $hasil->lihatdata();
  37. ?>
  38. <table width="500" border="1" >
  39.  
  40. <tr >
  41. <th><center><b>No</b></center></th>
  42. <th><center><b>Nim</b></center></th>
  43. <th><center><b>Tahun</b></center></th>
  44. <th><center><b>Nama</b></center></th>
  45. <th><center><b>Alamat</b></center></th>
  46. </tr>
  47.  
  48. <?php
  49. $no=1;
  50. foreach ($hasil as $data) {
  51. ?>
  52. <tr>
  53. <td><center><?php echo $no; ?></center></td>
  54. <td><center><?php echo $data['nim']; ?></center></td>
  55. <td><center><?php echo $data['thang']; ?></center></td>
  56. <td><center><?php echo $data['nama']; ?></center></td>
  57. <td><center><?php echo $data['alamat']; ?></center></td>
  58. </tr>
  59. <?php
  60. $no++;}
  61. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement