Membuat Database terlebih dahulu:
create database `db_tutorial`;
setelah itu membuat table:CREATE TABLE IF NOT EXISTS `tb_student` (
`id` int(11) NOT NULL,
`name` varchar(20) DEFAULT NULL,
`address` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
`id` int(11) NOT NULL,
`name` varchar(20) DEFAULT NULL,
`address` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Membuat file koneksi ke php
file --> connect.php :
<?php
$host = "localhost";
$user = "root";
$pass = "";
$dbName = "db_tutorial";
mysql_connect($host, $user, $pass);
mysql_select_db($dbName)
or die ("Connect Failed !! : ".mysql_error());
?>
Dibuatlah form untuk pencarian
File --> formsearching.php :<html>
<head>
<title> Halaman Pencarian </title>
</head>
<body>
<form name="form_cari" method="post" action="search_exe.php">
<table width="400" border="5" align="center" cellpadding="5">
<tr bgcolor="gold">
<td height="25" colspan="3">
<strong> PENCARIAN DATA MAHASISWA UNPAK </strong>
</td>
</tr>
<tr> <td> Name </td>
<td> <input type="text" name="name"> </td>
</tr>
<td></td>
<td> <input type="SUBMIT" name="SUBMIT" id="SUBMIT" value="search" > </td>
</table>
</form>
</body>
</html>
<body background="image/2010-happy-chirstmas-wallpaper.jpeg">
Kemudian membuat file proses pencarian dan disimpan dengan nama search_exe.php
search_exe.php :
<?php
include "connect.php";
$name= $_POST['name']; //get the nama value from form
$q = "SELECT * from tb_student where name like '%$name%' "; //query to get the search result
$result = mysql_query($q); //execute the query $q
echo "<center>";
echo "<h2> Hasil Pencarian yang anda temukan </h2>";
echo "<table border='10' cellpadding='9' cellspacing='7'>";
echo "
<tr bgcolor='gold'>
<td>No</td>
<td>Nama Mahasiswa</td>
<td>Alamat</td>
</tr>";
while ($data = mysql_fetch_array($result)) { //fetch the result from query into an array
echo "
<tr>
<td>".$data['id']."</td>
<td>".$data['name']."</td>
<td>".$data['address']."</td>
</tr>";
}
echo "</table>";
?>
<body background="image/2010-happy-chirstmas-wallpaper.jpeg">
Selamat Mencoba ^^
Source : http://echorossoneri.blogspot.com/2012/01/cara-membuat-aplikasi-searching-dengan.html
Anda ingin mencari refrensi dan contoh program lengkap ? Kami ada. Sekarang Anda bisa mencari PHP Aplikasi Untuk Skripsi Informatika di situs ini : http://www.bunafitkomputer.com. Koleksi program lengkap di sana, proyek PHP dan MySQL, juga jQuery dan Framework. Bukunya juga ada.
No comments:
Post a Comment