1. inc-db.php
2. search.php
3. fungsi.php
Source Code :
3. inc-db.php
<?php
mysql_connect('localhost','root','');
mysql_select_db('db_ruangprogramer');
?>
1. search.php
<?php
error_reporting(0);
include('../inc-db.php');
include('function.php');
//$sqlShow="SELECT * from tb_mahasiswa";
//$result=mysql_query($sqlShow);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form2" name="form2" method="post" action="">
<table width="200" border="0">
<tr>
<td>table</td>
<td>:</td>
<td><label for="select"></label>
<select name="select" id="select">
<option value="nim">Nim</option>
<option value="nama">Nama</option>
<option value="alamat">Alamat</option>
</select>
</td>
</tr>
<tr>
<td>data</td>
<td>:</td>
<td>
<input type="text" name="frm_data" id="frm_data" />
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>
<input type="submit" name="tombol" value="Search" />
</td>
</tr>
<?php
if($_POST['tombol']=='Search'){
echo cari_data();
}else
echo tampil_data();
?>
</body>
</html>
2. fungsi.php
<?php
function tampil_data(){
$sqlShow="SELECT * from tb_mahasiswa";
$result=mysql_query($sqlShow);
echo"<table width='442' border='1'>
<tr>
<td width='116'><b>Nim</b></td>
<td width='192'><b>Nama</b></td>
<td width='112'><b>Alamat</b></td>
</tr>";
while($data=mysql_fetch_array($result)){
echo"<tr>
<td>".$data['nim']." </td>
<td>".$data['nama']."</td>
<td>".$data['alamat']."</td>
</tr>";
}
echo"</table>";
}
function cari_data (){
$var_table=$_POST['select'];
$var_data=$_POST['frm_data'];
//echo $var_table." | ".$var_data;
//exit;
$sqlShow="SELECT * from tb_mahasiswa where ".$var_table." LIKE '%".$var_data."%' ";
//echo $sqlShow;
//exit;
$result=mysql_query($sqlShow);
?>
<table width="442" border="1">
<tr>
<td width="116">Nim</td>
<td width="192">Nama</td>
<td width="112">Alamat</td>
</tr>
<?php
while($data=mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $data['nim']; ?></td>
<td><?php echo $data['nama']; ?></td>
<td><?php echo $data['alamat']; ?></td>
</tr>
<?php
}
?>
</table>
<?php
}
?>
donwload file
2. search.php
3. fungsi.php
Source Code :
3. inc-db.php
<?php
mysql_connect('localhost','root','');
mysql_select_db('db_ruangprogramer');
?>
1. search.php
<?php
error_reporting(0);
include('../inc-db.php');
include('function.php');
//$sqlShow="SELECT * from tb_mahasiswa";
//$result=mysql_query($sqlShow);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form2" name="form2" method="post" action="">
<table width="200" border="0">
<tr>
<td>table</td>
<td>:</td>
<td><label for="select"></label>
<select name="select" id="select">
<option value="nim">Nim</option>
<option value="nama">Nama</option>
<option value="alamat">Alamat</option>
</select>
</td>
</tr>
<tr>
<td>data</td>
<td>:</td>
<td>
<input type="text" name="frm_data" id="frm_data" />
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>
<input type="submit" name="tombol" value="Search" />
</td>
</tr>
<?php
if($_POST['tombol']=='Search'){
echo cari_data();
}else
echo tampil_data();
?>
</body>
</html>
2. fungsi.php
<?php
function tampil_data(){
$sqlShow="SELECT * from tb_mahasiswa";
$result=mysql_query($sqlShow);
echo"<table width='442' border='1'>
<tr>
<td width='116'><b>Nim</b></td>
<td width='192'><b>Nama</b></td>
<td width='112'><b>Alamat</b></td>
</tr>";
while($data=mysql_fetch_array($result)){
echo"<tr>
<td>".$data['nim']." </td>
<td>".$data['nama']."</td>
<td>".$data['alamat']."</td>
</tr>";
}
echo"</table>";
}
function cari_data (){
$var_table=$_POST['select'];
$var_data=$_POST['frm_data'];
//echo $var_table." | ".$var_data;
//exit;
$sqlShow="SELECT * from tb_mahasiswa where ".$var_table." LIKE '%".$var_data."%' ";
//echo $sqlShow;
//exit;
$result=mysql_query($sqlShow);
?>
<table width="442" border="1">
<tr>
<td width="116">Nim</td>
<td width="192">Nama</td>
<td width="112">Alamat</td>
</tr>
<?php
while($data=mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $data['nim']; ?></td>
<td><?php echo $data['nama']; ?></td>
<td><?php echo $data['alamat']; ?></td>
</tr>
<?php
}
?>
</table>
<?php
}
?>
donwload file
Tidak ada komentar:
Posting Komentar