Contoh Script Search Dalam PHP
================================================================================================
PETUNJUK PENGGUNAAN!!!
TULISAN BERWARNA MERAH = DIGANTI SEPERTI APA KAMU MENAMAINYA SAAT MENYIMPAN SCRIPT KAMU DI HTDOCS.
TULISAN BERWARNA UNGU = DIGANTI NAMANYA SEPERTI KALIAN BAGAIMANA MENYIMPANNYA DALAM TABEL DATABASE LOCALHOST.
TULISAN BERWARNA HIJAU = DIGANTI BERDASARKAN NAMA TABEL YANG KALIAN GUNAKAN DI DATABASE LOCALHOST.
================================================================================================
<html>
<head>
<title></title>
</head>
<body >
<?php
include 'koneksi.php';
?>
<center><form action="searchbuku.php" method="get">
<label>Cari :</label>
<input type="text" name="cari">
<input type="submit" value="Cari">
</form>
<br>
<?php
if(isset($_GET['cari'])){
$cari = $_GET['cari'];
echo "<b>Hasil pencarian : ".$cari."</b>";
}
?>
<center><table width="0" border="10" cellspacing="0" cellpadding="20">
<tr>
<th>No</th>
<th>ID Buku</th>
<th>Judul</th>
<th>Tahun Terbit</th>
<th>Jenis Buku</th>
<th>Status</th>
<th><center>opsi</center></th>
</tr>
<?php
if(isset($_GET ['cari'])){
$cari = $_GET['cari'];
$data = mysqli_query($koneksi,"select * from buku where judul like '%".$cari."%'");
}else{
$data = mysqli_query($koneksi,"select * from buku");
}
$no = 1 ;
while($d = mysqli_fetch_array ($data)){
?>
<tr>
<td><?php echo $no++; ?></td>
<td><?php echo $d['id_buku'];?></td>
<td><?php echo $d['judul'];?></td>
<td><?php echo $d['tahun_terbit'];?></td>
<td><?php echo $d['jenis_buku'];?></td>
<td><?php echo $d['status'];?></td>
<td> <a href="updatebuku.php?id=<?php echo $d['id_buku']; ?>"> update </a>
<a href="deletebuku.php?id=<?php echo $d['id_buku']; ?>"> delete </a>
</tr>
<?php } ?>
</table><br><br>
<td> <button><a href="showbuku.php">SHOW ALL</a></button>
</form>
</body>
</html>
Comments
Post a Comment