Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ini file koneksi.php
- <?php
- $host="localhost";
- $username="root";
- $password="";
- $db_name="oop";
- mysql_connect($host,$username,$password,$db_name) or DIE("Koneksi ke DB gagal!");
- mysql_select_db($db_name)or DIE ("Nama DB tidak ada");
- ?>
- //ini file class.php
- <?php
- require 'koneksi.php';
- //Class Database
- class operasi{
- function lihatdata(){
- $tampil=mysql_query("SELECT nim,thang,nama,alamat From mahasiswa;");
- while($row=mysql_fetch_array($tampil))
- $data[]=$row;
- return $data;
- }
- }
- ?>
- //ini file yang manggil show.php
- <?php
- require_once 'classoperasi.php';
- $hasil=new operasi();
- $hasil->lihatdata();
- ?>
- <table width="500" border="1" >
- <tr >
- <th><center><b>No</b></center></th>
- <th><center><b>Nim</b></center></th>
- <th><center><b>Tahun</b></center></th>
- <th><center><b>Nama</b></center></th>
- <th><center><b>Alamat</b></center></th>
- </tr>
- <?php
- $no=1;
- foreach ($hasil as $data) {
- ?>
- <tr>
- <td><center><?php echo $no; ?></center></td>
- <td><center><?php echo $data['nim']; ?></center></td>
- <td><center><?php echo $data['thang']; ?></center></td>
- <td><center><?php echo $data['nama']; ?></center></td>
- <td><center><?php echo $data['alamat']; ?></center></td>
- </tr>
- <?php
- $no++;}
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement