Postingan lainnya
Menyembunyikan data table, dan data akan muncul jika melakukan pencarian.
hallo assalamualaikum, mau bertanya gimana yah caranya atau harus pakek apa supaya data di table itu kosong dan data muncul di table ketika melakukan pencarian terlebih dahulu.
<?php
include 'config.php';
?>
<form action="index.php" method="get">
<label>Cari :</label>
<input type="text" name="cari">
<input type="submit" value="Cari">
</form>
<?php
if(isset($_GET['cari'])){
$cari = $_GET['cari'];
echo "<b>Hasil pencarian : ".$cari."</b>";
}
?>
<table border="1">
<tr>
<th>No</th>
<th>Nama</th>
<th>jurusan</th>
<th>semester</th>
</tr>
<?php
if(isset($_GET['cari'])){
$cari = $_GET['cari'];
$data = mysql_query("select * from mhs where nama like '%".$cari."%' or jurusan like '%".$cari."%' or semester like '%".$cari."%'");
}
else{
$data = mysql_query("select * from mhs");
}
$no = 1;
while($d = mysql_fetch_array($data)){
?>
<tr>
<td><?php echo $no++; ?></td>
<td><?php echo $d['nama']; ?></td>
<td><?php echo $d['jurusan']; ?></td>
<td><?php echo $d['semester']; ?></td>
</tr>
<?php
}
?>
</table>
1 Jawaban:
Jawaban Terpilih
jadi datanya harus dicari dulu baru muncul? kalau ya, coba ini :
<pre> <table border="1"> <tr> <th>No</th> <th>Nama</th> <th>jurusan</th> <th>semester</th> </tr> <?php if(isset($_GET['cari'])){ $cari = $_GET['cari']; $data = mysql_query("select * from mhs where nama like '%".$cari."%' or jurusan like '%".$cari."%' or semester like '%".$cari."%'");
$no = 1;
while($d = mysql_fetch_array($data)){
?> <tr> <td><?php echo $no++; ?></td> <td><?php echo $d['nama']; ?></td> <td><?php echo $d['jurusan']; ?></td> <td><?php echo $d['semester']; ?></td> </tr> <?php } } ?> </table> </pre>