SHARE
TWEET

Untitled

a guest Jun 8th, 2017 59 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 = "0l4lupa3N"; //password isi sesuai seting server Anda.
  12. $db_name = "yudo";  // 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.  
  19. <table width="600" align="center" bgcolor="#CC9900"  border="1">
  20. <tr>
  21.     <th>No</th>
  22.     <th>Nama</th>
  23.     <th>JK</th>
  24.     <th></th>
  25. </tr>
  26. <?php
  27. // menampilkan data
  28.  
  29. if ((isset($_POST['submit'])) AND ($_POST['search'] <> "")) {
  30.   $search = $_POST['search'];
  31.   $sql = mysql_query("SELECT * FROM siswa WHERE nama LIKE '%$search%' ") or die(mysql_error());
  32.   //menampilkan jumlah hasil pencarian
  33.   $jumlah = mysql_num_rows($sql);
  34.   if ($jumlah > 0) {
  35.     echo '<p>Ada '.$jumlah.' data yang sesuai.</p>';
  36.    
  37.         while ($res=mysql_fetch_array($sql)) {
  38.         $nomor++;
  39.     echo "<tr>";
  40.    echo "<td>".$nomor."</td>";
  41.    echo "<td>".$res['nama']."</td>";
  42.    echo "<td>".$res['sex']."</td>";
  43.       }
  44.        echo "</table><br>";
  45.   }
  46.   else {
  47.    // menampilkan pesan zero data
  48.     echo 'Maaf, hasil pencarian tidak ditemukan.';
  49.   }
  50. }
  51. else { echo 'Masukkan dulu kata kuncinya';}
  52. ?>
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