Cara menampilkan database di PHP
Langkah awal yang harus diperhatikan adalah membuat database terdahulu sebagai contoh :
database : ip_pool_speedy
tabel : ip_pool
tampilan di server xampp terlihat seperti gambar verikut :
hasil akhir dari databaase yang ditampilkan di web browser seperti tampilan di bawah ini :
untuk scriptnya :
<?
$conn =mysql_connect("localhost","root","");
$db = mysql_select_db("ip_pool_speedy",$conn);
$sql = "select * from ip_pool";
$hasil = mysql_query($sql,$conn);
?>
<style type="text/css">
<!--
.style1 {font-size: 10px}
-->
</style>
<br />
</p>
<table width="520" border="1" align="center" cellpadding="2" cellspacing="0">
<tr>
<td width="43" bgcolor="#9999FF"><div align="center"><span class="style1">IP</span></div></td>
<td width="20" bgcolor="#9999FF"><div align="center"><span class="style1">UCS</span></div></td>
<td width="43" bgcolor="#9999FF"><div align="center"><span class="style1">Area</span></div></td>
<td width="40" bgcolor="#9999FF"><div align="center"><span class="style1">Bras</span></div></td>
<td width="52" bgcolor="#9999FF"><div align="center"><span class="style1">Jenis IP</span></div></td>
<td width="61" bgcolor="#9999FF"><div align="center"><span class="style1">Blok IP</span></div></td>
<td width="54" bgcolor="#9999FF"><div align="center"><span class="style1">Tgl Request</span></div></td>
<td width="49" bgcolor="#9999FF"><div align="center"><span class="style1">Tgl Done</span></div></td>
<td width="51" bgcolor="#9999FF"><div align="center"><span class="style1">Pic</span></div></td>
<td width="45" bgcolor="#9999FF"><div align="center"><span class="style1">Status</span></div></td>
</tr>
<?php
while ($ip_pool = mysql_fetch_row($hasil)){
?>
<tr>
<td><div align="center"><span class="style1"><?php echo $ip_pool[1]; ?></span></div></td>
<td><div align="center"><span class="style1"><?php echo $ip_pool[2]; ?></span></div></td>
<td><div align="center"><span class="style1"><?php echo $ip_pool[3]; ?></span></div></td>
<td><div align="center"><span class="style1"><?php echo $ip_pool[4]; ?></span></div></td>
<td><div align="center"><span class="style1"><?php echo $ip_pool[5]; ?></span></div></td>
<td><div align="center"><span class="style1"><?php echo $ip_pool[6]; ?></span></div></td>
<td><div align="center"><span class="style1"><?php echo $ip_pool[7]; ?></span></div></td>
<td><div align="center"><span class="style1"><?php echo $ip_pool[8]; ?></span></div></td>
<td><div align="center"><span class="style1"><?php echo $ip_pool[9]; ?></span></div></td>
<td><div align="center"><span class="style1"><?php echo $ip_pool[10]; ?></span></div></td>
</tr>
<?php } ?>
atau download scriptnya di sini$conn =mysql_connect("localhost","root","");
$db = mysql_select_db("ip_pool_speedy",$conn);
$sql = "select * from ip_pool";
$hasil = mysql_query($sql,$conn);
?>
<style type="text/css">
<!--
.style1 {font-size: 10px}
-->
</style>
<br />
</p>
<table width="520" border="1" align="center" cellpadding="2" cellspacing="0">
<tr>
<td width="43" bgcolor="#9999FF"><div align="center"><span class="style1">IP</span></div></td>
<td width="20" bgcolor="#9999FF"><div align="center"><span class="style1">UCS</span></div></td>
<td width="43" bgcolor="#9999FF"><div align="center"><span class="style1">Area</span></div></td>
<td width="40" bgcolor="#9999FF"><div align="center"><span class="style1">Bras</span></div></td>
<td width="52" bgcolor="#9999FF"><div align="center"><span class="style1">Jenis IP</span></div></td>
<td width="61" bgcolor="#9999FF"><div align="center"><span class="style1">Blok IP</span></div></td>
<td width="54" bgcolor="#9999FF"><div align="center"><span class="style1">Tgl Request</span></div></td>
<td width="49" bgcolor="#9999FF"><div align="center"><span class="style1">Tgl Done</span></div></td>
<td width="51" bgcolor="#9999FF"><div align="center"><span class="style1">Pic</span></div></td>
<td width="45" bgcolor="#9999FF"><div align="center"><span class="style1">Status</span></div></td>
</tr>
<?php
while ($ip_pool = mysql_fetch_row($hasil)){
?>
<tr>
<td><div align="center"><span class="style1"><?php echo $ip_pool[1]; ?></span></div></td>
<td><div align="center"><span class="style1"><?php echo $ip_pool[2]; ?></span></div></td>
<td><div align="center"><span class="style1"><?php echo $ip_pool[3]; ?></span></div></td>
<td><div align="center"><span class="style1"><?php echo $ip_pool[4]; ?></span></div></td>
<td><div align="center"><span class="style1"><?php echo $ip_pool[5]; ?></span></div></td>
<td><div align="center"><span class="style1"><?php echo $ip_pool[6]; ?></span></div></td>
<td><div align="center"><span class="style1"><?php echo $ip_pool[7]; ?></span></div></td>
<td><div align="center"><span class="style1"><?php echo $ip_pool[8]; ?></span></div></td>
<td><div align="center"><span class="style1"><?php echo $ip_pool[9]; ?></span></div></td>
<td><div align="center"><span class="style1"><?php echo $ip_pool[10]; ?></span></div></td>
</tr>
<?php } ?>
0 comments:
Untuk sisipkan emoticon, taruh kode di komentar dan beri 1 spasi sebelum kode.