[trick] Pop Up Window Advance Dengan PHP Dan Javascript

database

Koneksi.php


$server = "localhost";
$username = "root";
$password = "12345";
$database = "buku";

mysql_connect($server,$username,$password) or die("Koneksi gagal");
mysql_select_db($database) or die("Database tidak bisa dibuka");

?

Searchpopup.php


<?php
echo"<form id='form' name='form' method='post' action=''>
 <table width='314' border='0' cellspacing='0' cellpadding='0'>
 <tr>
 <td width='80'>Nama</td>
 <td width='368'>
 <input type='text' name='nama'/>
 <input name='cari2' type='button' id='cari2' onclick=window.open 
('popupsearch.php','','height=200,width=480,scrollbars=yes') value='Search' 
/>
 </td>
 </tr>
 <tr>
 <td>Alamat</td>
 <td><input type='text' name='alamat' /></td>
 </tr>
 <tr>
 <td>Tlp</td>
 <td><input type='text' name='tlp' /></td>
 </tr>
 </table>
</form>";
?>


popsearch.php


<style type="text/css">
<!--
.head_tbl {
font-size: 14px;
font-weight: bold;
font-family:Verdana, Arial, Helvetica, sans-serif;
text-transform: uppercase;
color: #FFFFFF;
background-color: #006699;
}

.style9 { color: #000000;
font-size: 9pt;
font-weight: normal;
font-family: Arial;
}
-->
</style>
<script type="text/javascript">
function ambil(a){
window.opener.document.form.nama.value = document.getElementById("nama"+a+"").innerHTML;
window.opener.document.form.alamat.value = document.getElementById("alamat"+a+"").innerHTML;
window.opener.document.form.tlp.value = document.getElementById("tlp"+a+"").innerHTML;
window.close();

}

</script>
<table width="100%" border="0">
<tr>
<td><form id="form" name="form1" method="post" action="">
<label>
Nama
<input type="text" name="cari" id="cari" />
</label>
<label>
<input type="submit" name="button" id="button" value="cari" onClick="pencarian()" />
</label>
</form></td>
</tr>
</table>
<table width="458" border="1">
<tr class="head_tbl">
<td width="122" bgcolor="#006699"><div align="center">Nama</div></td>
<td width="224" bgcolor="#006699"><div align="center">Alamat</div></td>
<td width="90" bgcolor="#006699"><div align="center"><span class="style1">Tlp</span></div></td>
</tr>
<?php
error_reporting(0);
include"koneksi.php";
$hal = $_GET[hal];
if(!isset($_GET['hal'])){
$page = 1;
} else {
$page = $_GET['hal'];
}
$jmlperhalaman = 20; // jumlah record per halaman
$offset = (($page * $jmlperhalaman) - $jmlperhalaman);
if($_GET['flag']==1)
{
$cari=$_GET['cari'];
$sql=mysql_query("select * from pelanggan where nama LIKE '%".$cari."%' limit $offset, $jmlperhalaman") or die (mysql_error());

}
else
{

$sql=mysql_query("select * from pelanggan limit $offset, $jmlperhalaman") or die (mysql_error());
}
$i=1;
while($rs=mysql_fetch_array($sql))
{
if($i%2==0)
{
echo("<tr onclick=\"ambil('$rs[0]')\" bgcolor=\"#FFEEEE\">");
}
else
{
echo("<tr onclick=\"ambil('$rs[0]')\">");
}?>
<td width="122" id="nama<?=$rs[0];?>"><?=$rs[nama];?></td>
<td width="224" id="alamat<?=$rs[0];?>"><?=$rs[alamat];?></td>
<td width="90" id="tlp<?=$rs[0];?>"><?=$rs[tlp];?></td>
<? $i++;
}
?>
</table>
<?

if($_GET['flag']==1)
{
$cari=$_GET['cari'];
$total_record = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM pelanggan where nama LIKE '%".$cari."%'"),0);
}
else
{
$total_record = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM pelanggan"),0);
}
$total_halaman = ceil($total_record / $jmlperhalaman);
echo "<center>";
$perhal=4;
if($hal > 1){
$prev = ($page - 1);
if($_GET['flag']==1)
{
echo "<a href=$_SERVER[PHP_SELF]?hal=$prev&cari=$_GET[cari]&flag=1> << </a> ";
}
else
{
echo "<a href=$_SERVER[PHP_SELF]?hal=$prev> << </a> ";
}
}
if($total_halaman<=10){
$hal1=1;
$hal2=$total_halaman;
}else{
$hal1=$hal-$perhal;
$hal2=$hal+$perhal;
}
if($hal<=5){
$hal1=1;
}
if($hal<$total_halaman){
$hal2=$hal+$perhal;
}else{
$hal2=$hal;
}
for($i = $hal1; $i <= $hal2; $i++){
if(($hal) == $i){
echo "[<b>$i</b>] ";
} else {
if($i<=$total_halaman){
if($_GET['flag']==1)
{
echo "<a href=$_SERVER[PHP_SELF]?hal=$i&cari=$_GET[cari]&flag=1>$i</a> ";
}
else
{
echo "<a href=$_SERVER[PHP_SELF]?hal=$i>$i</a> ";
}
}
}
}
if($hal < $total_halaman){
$next = ($page + 1);
if($_GET['flag']==1)
{
echo "<a href=$_SERVER[PHP_SELF]?hal=$next&cari=$_GET[cari]&flag=1> >> </a>";
}
else
{
echo "<a href=$_SERVER[PHP_SELF]?hal=$next> >> </a>";
}
}
echo "</center>";
?>
<script type="text/javascript">
function pencarian()
{
var cari=document.getElementById('cari').value;
document.form1.action="popupsearch.php?flag=1&cari="+cari;
document.form1.submit();
}
</script>

hasil_akhir

 

Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: