SHARE
TWEET

Untitled

a guest Jun 5th, 2017 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <strong>PENCARIAN:</strong><br>
  2. <form action="<?$_SERVER['PHP_SELF']?>" method="post" name="pencarian" id="pencarian">
  3.   <input type="text" name="search" id="search">
  4.   <input type="submit" name="submit" id="submit" value="CARI">
  5. </form>
  6.  
  7. <?php
  8. // konfigurasi
  9. $db_host = "localhost";  // nama host
  10. $db_user = "root";  // username mysql
  11. $db_pass = ""; //password isi sesuai seting server Anda.
  12. $db_name = "pencarian";  // karena nama database yang kita buat adalah pencarian
  13.  
  14. // koneksi ke database
  15. $link = mysql_pconnect ($db_host, $db_user, $db_pass) or die ("Ga bisa connect");
  16. mysql_select_db ($db_name) or die ("Ga bisa select database");
  17.  
  18. // menampilkan data
  19.  
  20. if ((isset($_POST['submit'])) AND ($_POST['search'] <> "")) {
  21.   $search = $_POST['search'];
  22.   $sql = mysql_query("SELECT * FROM siswa WHERE nama LIKE '%$search%' ") or die(mysql_error());
  23.   //menampilkan jumlah hasil pencarian
  24.   $jumlah = mysql_num_rows($sql);
  25.   if ($jumlah > 0) {
  26.     echo '<p>Ada '.$jumlah.' data yang sesuai.</p>';
  27.    
  28.         while ($res=mysql_fetch_array($sql)) {
  29.         $nomor++; echo $nomor.'. ';
  30.         echo $res[nama].'<br>';
  31.       }
  32.   }
  33.   else {
  34.    // menampilkan pesan zero data
  35.     echo 'Maaf, hasil pencarian tidak ditemukan.';
  36.   }
  37. }
  38. else { echo 'Masukkan dulu kata kuncinya';}
  39. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top