<?php
$host = "localhost";
$user = "root";
$password = "";
$dbname = "dbcoba";
$koneksi = mysqli_connect($host,$user,$password);
$dbkonek = mysqli_select_db($koneksi,$dbname) or die("error euy ");
if(isset($_GET['txtnama'])) {
$search = str_replace(" ","|",$_GET['txtnama']);
$sql= " SELECT * FROM tbpegawai WHERE nama REGEXP '$search' ";
$run = mysqli_query($koneksi,$sql) or die(mysqli_error($koneksi));
$row = mysqli_fetch_assoc($run);
$total = mysqli_num_rows($run);
}
?>
<body>
<form action="cari.php" method="GET">
<input type="text" name="txtnama" id="txtnama" placeholder="Cari" value="<?php echo $_GET['txtnama']; ?>">
<button type="submit" value="Cari" > Cari</button>
</form>
<?php if($total>0) { ?>
<table border="1" width="500">
<thead>
<tr>
<th> <strong>Hasil Cari <?php echo $total ; ?></strong> </th>
</tr>
</thead>
<tbody>
<?php do{ ?>
<tr>
<td><?php echo $row['nama']; ?> </td>
</tr>
<?php } while($row=mysqli_fetch_assoc($run)) ;?>
</tbody>
</table>
<?php } ?>
</body>
Regards,
HERY PURNAMA