simpan script di bawah dengan nama index.php
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="seacrh.php" method="POST">
<input type="text" name="data_cari"><br/>
<select name="kategori">
<option value="nim">Nim</option>
<option value="nama_mhs">Nama</option>
<option value="alamat">Alamat</option>
</select>
<input type="submit" value="cari">
</form>
</body>
</html>
simpan script di bawah dengan nama search.php
<?php
$kata_kunci = $_POST['data_cari'];
$cari = $_POST['kategori'];
$MyDb = new mysqli("localhost","root","","akademik");
$query= "SELECT * FROM mhs where $cari LIKE'%$kata_kunci%'";
$hasilCari = $MyDb->query($query);
if($hasilCari->num_rows == 0){
echo "DATA TIDAK DITEMUKAN";
}else{
while($data = mysqli_fetch_array($hasilCari)){
echo "Nim :".$data['nim']."<br/>";
echo "Nama : ".$data['nama_mhs']."<br/>";
echo "Alamat : ".$data['alamat']."<br/>";
}
}
?>
NOTE: Jangan lupa di buatkan terlebih dahulu database nya
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="seacrh.php" method="POST">
<input type="text" name="data_cari"><br/>
<select name="kategori">
<option value="nim">Nim</option>
<option value="nama_mhs">Nama</option>
<option value="alamat">Alamat</option>
</select>
<input type="submit" value="cari">
</form>
</body>
</html>
simpan script di bawah dengan nama search.php
<?php
$kata_kunci = $_POST['data_cari'];
$cari = $_POST['kategori'];
$MyDb = new mysqli("localhost","root","","akademik");
$query= "SELECT * FROM mhs where $cari LIKE'%$kata_kunci%'";
$hasilCari = $MyDb->query($query);
if($hasilCari->num_rows == 0){
echo "DATA TIDAK DITEMUKAN";
}else{
while($data = mysqli_fetch_array($hasilCari)){
echo "Nim :".$data['nim']."<br/>";
echo "Nama : ".$data['nama_mhs']."<br/>";
echo "Alamat : ".$data['alamat']."<br/>";
}
}
?>
NOTE: Jangan lupa di buatkan terlebih dahulu database nya