Tolong pilih kategori sesuai, jenis posting (diskusi atau bukan) dan sertakan tag/topik yang sesuai seperti komputer, java, php, mysql, dll. Promosi atau posting tidak pada tempatnya akan kami hapus!
- Bagi Anda yang ingin mendaftar, baca link berikut:
http://diskusiweb.com/discussion/50491/how-to-registrasi-diskusiweb-com-baca-ini-terlebih-dahulu
- Cara menyisipkan kode program supaya tampil rapi dan terformat dengan baik di diskusiweb.com: http://www.diskusiweb.com/discussion/50415/cara-menyisipkan-kode-program-di-diskusiweb-com
- Cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

Help donk...Search page kaga jalan ?

ganti jadi


$keyword = $_POST["keyword"];
ganti jadi
$keyword = urldecode($_GET["keyword"]);

$halaman_str .= "[First] ";
[b]semua link halaman paging, tambah[/b]
$halaman_str .= "[First] ";



btw, tuh keyword, filter dulu, jangan langsung masuk query
Tagged:

Comments

  • $halaman_str .= "<a href='?id=2&hal=$i' title='Halaman $hal'>$hal</a> ";

    Paramternya mana? Seharusnya formnya pakai get bukan post
  • masih blom...bisa mas goku :(

    yang lain ada yang bisa bantu ?
  • Perubaha skrip anda seperti apa? Terus nggk bisanya dimana?
  • <form name="search" method="post" action="" align="center">
    ganti jadi
    <form name="search" method="get" action="" align="center">

    $keyword = $_POST["keyword"];
    ganti jadi
    $keyword = urldecode($_GET["keyword"]);

    $halaman_str .= "<a href='?id=2&hal=0' title='Halaman pertama'>[First]</a> ";
    semua link halaman paging, tambah
    $halaman_str .= "<a href='?id=2&hal=0&keyword=".urlencode($keyword)."' title='Halaman pertama'>[First]</a> ";



    btw, tuh keyword, filter dulu, jangan langsung masuk query
  • katanya temenku tambahin gini,

    $sql=select * from TabelApa where nama_pelanggan like '%$keyword%';
  • Originally posted by kribo46
    katanya temenku tambahin gini,

    $sql=select * from TabelApa where nama_pelanggan like '%$keyword%';
    lha emang sudah spt itu :

    $keyword = $_POST["keyword"];
    if($keyword!=""){
    $sql .= " where Nama_Pelanggan like '%$keyword%'";
    }

    :D

    *piye to*
  • Originally posted by badman
    <form name="search" method="post" action="" align="center">
    ganti jadi
    <form name="search" method="get" action="" align="center">

    $keyword = $_POST["keyword"];
    ganti jadi
    $keyword = urldecode($_GET["keyword"]);

    $halaman_str .= "<a href='?id=2&hal=0' title='Halaman pertama'>[First]</a> ";
    semua link halaman paging, tambah
    $halaman_str .= "<a href='?id=2&hal=0&keyword=".urlencode($keyword)."' title='Halaman pertama'>[First]</a> ";



    btw, tuh keyword, filter dulu, jangan langsung masuk query

    aku udah samain..kayak badman punya..tapi masih blom bisa ?
    dia tetep larinya ke awal...ke index...blank ga ada hasilnya ?

    ======================================

    <?
    session_start();
    if (!isset($_SESSION)) {
    header("Location: ../index.php");
    }
    ?>

    <html>
    <head>
    <title>View Registrasi</title>
    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
    <link href="css/dzt.css" rel="stylesheet" type="text/css">
    </head>
    <script>
    function confirmDelete(delUrl) {
    if (confirm("Are you sure you want to delete")) {
    document.location = delUrl;
    }
    }
    </script>


    <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

    <center>
    <font class="hsmf">View Customer Registration </font>
    </center>
    <br>
    <table width="339" height="33" border="0" align="center">
    <form name="search" method="get" action="" align="center">
    <tr>
    <td width="76"><font class="pipe">Search By</font> :</td>
    <td width="128"><input name="keyword" type="text"></td>
    <td width="121"><input name="search" type="image" value="search" src="../images/arrow.gif" width="16" height="15"></td>
    </tr></form>
    </table>


    <table width="719" height="64" border="1" align="center">
    <tr>
    <td width="18" height="15" class="tableHead" align="center">No</td>
    <td width="151" class="tableHead" align="center">Date of Registration </td>
    <td width="176" class="tableHead" align="center">Customer ID </td>
    <td width="150" class="tableHead" align="center">Name</td>
    <td width="275" class="tableHead" align="center">Address</td>
    <td width="32" class="tableHead" align="center">Flag</td>
    <td width="35" class="tableHead" align="center">Details</td>
    <td width="38" class="tableHead" align="center">Edit</td>
    <td width="50" class="tableHead" align="center">Delete</td>
    </tr>

    <?

    // ambil isi dari file utama.php

    require("../koneksi/utama.php");


    // hubungkan ke database
    $link=open_connection();

    $perhalaman = 5; // tentukan jumlah data perhalaman

    // jika ada parameter halaman, ambil. jika tidak, isikan kosong
    $halaman = isset($_GET["hal"]) ? $_GET["hal"] : "0";

    // hitung posisi awal data (offset)
    $awal = $halaman * $perhalaman;
    $id=$awal;

    // query untuk ambil data.
    // rubah sesuai dengan kebutuhan (namatabel dan namafield untuk pengurutan)
    $query = "select * from tbl_registrasi order by Id limit $awal, $perhalaman";
    $query_jumlah = "select count(*) from tbl_registrasi";

    // search page
    $keyword = urldecode($_GET["keyword"]);
    if($keyword!=""){
    $sql .= " where Nama_Pelanggan like '%$keyword%'";
    }

    // ambil jumlah total data
    $rs_jumlah = mysql_query($query_jumlah) or die(mysql_error());
    $r = mysql_fetch_row($rs_jumlah);

    // hitung total halaman
    $total_halaman = ceil($r[0] / $perhalaman);

    // bentuk halaman, di sini intinya

    $halaman_str = ""; // kosongkan variabel

    // jika berada pada halaman ketiga atau lebih, tampilkan link [pertama]
    if ($halaman > 1)
    //$halaman_str .= "<a href='?id=2&hal=0' title='Halaman pertama'>[First]</a> ";
    $halaman_str .= "<a href='?id=2&hal=0&keyword=".urlencode($keyword)."' title='Halaman pertama'>[First]</a> ";
    // jika berada pada halaman kedua atau lebih, tampilkan link [sebelumnya]
    if ($halaman > 0)
    {
    $hal = $halaman - 1;
    $halaman_str .= "<a href='?id=2&hal=$hal&keyword=".urlencode($keyword)."' title='Halaman sebelumnya'>[Previous]</a> ";
    }

    // ambil semua nomor halaman
    for ($i = 0; $i < $total_halaman; $i++)
    {
    $hal = $i + 1;
    if ($i == $halaman) // jika halaman aktif, tidak usah diberi link
    $halaman_str .= "$hal ";
    else
    $halaman_str .= "<a href='?id=2&hal=$i&keyword=".urlencode($keyword)."' title='Halaman $hal'>$hal</a> ";
    }

    // jika bukan berada pada halaman terakhir
    if ($halaman < ($total_halaman - 1))
    {
    $hal = $halaman + 1;
    $halaman_str .= "<a href='?id=2&hal=$hal&keyword=".urlencode($keyword)."' title='Halaman berikutnya'>[Next]</a> ";
    }

    // jika bukan pada 2 halaman terakhir
    if ($halaman < ($total_halaman - 2))
    {
    $hal = $total_halaman - 1;
    $halaman_str .= "<a href='?id=2&hal=$hal&keyword=".urlencode($keyword)."' title='Halaman terakhir'>[Last]</a> ";
    }


    // baca data halaman ini
    $rs = mysql_query($query) or die(mysql_error());


    // putus hubungan dengan database
    mysql_close($link);


    // ambil isi masing-masing record
    while ($row = mysql_fetch_object($rs))
    {
    // mengambil isi setiap kolom

    $id++;
    $var_id=$row->Id;
    $var_nopel=$row->No_Pel;
    $var_flag=$row->Flag;
    $var_nama=$row->Nama_Pelanggan;
    $var_alamat=$row->Alamat;
    $var_tgl=$row->Tgl_Register;
    $var_tlhr=$row->Tmpt_lhr;
    $var_tgllhr=$row->Tgl_lhr;
    $var_jkel=$row->J_kel;
    $var_pekerjaan=$row->Pekerjaan;
    $var_selectid=$row->IdCard;
    $var_noid=$row->No_Id;
    $var_email=$row->Email;
    $var_Uinput=$row->input_by;


    ?>
    <tr>
    <td align="center" class="tableCnt">&nbsp;<? echo($id); ?>&nbsp;</td>
    <td class="tableCnt">&nbsp;<? echo($var_tgl);?></td>
    <td class="tableCnt">&nbsp;<? echo($var_nopel); ?></td>
    <td class="tableCnt">&nbsp;<? echo($var_nama); ?></td>
    <td class="tableCnt">&nbsp;<? echo($var_alamat); ?></td>
    <td align="center" class="tableCnt"><? if($var_flag==0){
    echo("Non Aktif");
    } else {
    echo("Aktif");
    } ?></td>
    <td align="center" class="tableCnt">&nbsp;<a href="registrasi_detail.php?id=24&idno=<? echo($var_id); ?>&nopel=<? echo($var_nopel); ?>&flag=<? echo($var_flag); ?>&nama=<? echo($var_nama); ?>&almt=<? echo($var_alamat); ?>&tgl=<? echo($var_tgl); ?>&tlhr=<? echo($var_tlhr); ?>&tgllhr=<? echo($var_tgllhr); ?>&jkel=<? echo($var_jkel); ?>&pekerjaan=<? echo($var_pekerjaan); ?>&idcard=<? echo($var_selectid); ?>&noid=<? echo($var_noid); ?>&email=<? echo($var_email); ?>&input=<? echo($var_Uinput); ?>">&nbsp;Details&nbsp;</a></td>
    <td class="tableCnt"><a href="index.php?id=21&idno=<? echo($var_id); ?>&nopel=<? echo($var_nopel); ?>&nama=<? echo($var_nama); ?>&almt=<? echo($var_alamat); ?>">&nbsp;EDIT</a></td>
    <td class="tableCnt"><a href="javascript :confirmDelete('index.php?id=23&idno=<? echo($var_id);?>')">&nbsp;DELETE</a></td>
    </tr>
    <?
    }
    ?>
    <tr>
    <td colspan="9" align="center" class="tableCnt">&nbsp;
    <?
    echo "$halaman_str";
    ?>
    </td>
    </tr>
    <tr><td> <a href="index.php?id=4" class="boxCek">New</a></td></tr>
    </table>


    </body>
    </html>
  • Ok kayaknya digabung ya ...

    <?php
    $sql="select * from tabel";
    if(isset($_GET)){
    $keywrod=urlencode($_GET);
    $sql.=" where nama like '%$keyword%'";
    }
    $qry=mysql_query($sql) or die (mysql_error());
    $per_halaman=10;

    //ambil jumlah page untuk mendapatkan offset

    $sql.=" limit $offset,$per_halaman";
    //lalu eksekusi deh querynya

    //form search
    //view data (secara default jika dipanggi tampil semua)
    //cetak paging
    ?>
  • Originally posted by Goku
    Ok kayaknya digabung ya ...

    <?php
    $sql="select * from tabel";
    if(isset($_GET)){
    $keywrod=urlencode($_GET);
    $sql.=" where nama like '%$keyword%'";
    }
    $qry=mysql_query($sql) or die (mysql_error());
    $per_halaman=10;

    //ambil jumlah page untuk mendapatkan offset

    $sql.=" limit $offset,$per_halaman";
    //lalu eksekusi deh querynya

    //form search
    //view data (secara default jika dipanggi tampil semua)
    //cetak paging
    ?>

    mas...goku, ini buat script yang pertama saya kirim apa yang kedua ?
    mohon pencerahannya...
  • Originally posted by Goku
    Kayaknya kamu menggambung view data sama search dalam 1 page ya. Coba klik link pagingnya. Di status bar muncul apa?

    iya...jadi satu page...
    emang ga boleh yah...mas :D

    bagusnya gimana mas...mohon petunjuknya...
    kalo emang harus di pisah...ya...nanti saya pisah...
    saya bikin gitu mau bikin simple aja sih :)
    ini linknya...mas goku

    ================================

    http://localhost/web/index.php?id=2&hal=0&keyword=
  • Kayaknya kamu menggambung view data sama search dalam 1 page ya. Coba klik link pagingnya. Di status bar muncul apa?
  • Originally posted by Goku
    Lah itu hanya kerangkanya saja. Yang lainnya silahkan dilengkapi :D Sesuaikan dengan skrip anda.

    Intinya saat pertama kali diload maka akan memilih semua datanya. Lalu dilihat variabel keyword. Apakah ada? Jika ada baru ditambahkan kondisi where. Gitu aja. Simpel kok :cool:

    oh...maksudnya bikin lagi dari awal...
    makasih...mas goku ;)
  • Lah itu hanya kerangkanya saja. Yang lainnya silahkan dilengkapi :D Sesuaikan dengan skrip anda.

    Intinya saat pertama kali diload maka akan memilih semua datanya. Lalu dilihat variabel keyword. Apakah ada? Jika ada baru ditambahkan kondisi where. Gitu aja. Simpel kok :cool:
  • Originally posted by Goku
    Perubaha skrip anda seperti apa? Terus nggk bisanya dimana?

    perubahannya sama paging aja...mas goku
    kalo pake script yang ini paging jalan...
    tapi nomer yang ada di tabel No itu selalu 1 s/d 5
    setiap di klik perhalaman paging...
    seharusnya page 1 = 1 s/d 5, page 2 = 6 s/d 10, dst...

    trus search jalan...akan tetapi kalo di klik pagingnya...
    dia balikl agi ke awal...harusnya kalo udah ketemu hasil
    pagingnya jalan untuk hasilnya aja...kalo ini ga jalan...
    bisa minta tolong bantuannya ?

    ===================================

    <?
    session_start();
    if (!isset($_SESSION)) {
    header("Location: ../index.php");
    }
    ?>

    <html>
    <head>
    <title>View Registrasi</title>
    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
    <link href="css/dzt.css" rel="stylesheet" type="text/css">
    </head>
    <script>
    function confirmDelete(delUrl) {
    if (confirm("Are you sure you want to delete")) {
    document.location = delUrl;
    }
    }
    </script>


    <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

    <center>
    <font class="hsmf">View Customer Registration </font>
    </center>
    <br>
    <table width="339" height="33" border="0" align="center">
    <form name="search" method="post" action="" align="center">
    <tr>
    <td width="181"><font class="pipe">Search By</font>
    <select name="cari">
    <option value="No_Pel">Customer ID&nbsp;</option>
    <option value="Nama_Pelanggan">Name&nbsp;</option>
    </select></td>
    <td width="124"><input name="keyword" type="text"></td>
    <td width="20"><input name="search" type="image" value="search" src="../images/arrow.gif" width="16" height="15"></td>
    </tr></form>
    </table>


    <table width="719" height="64" border="1" align="center">
    <tr>
    <td width="18" height="15" class="tableHead" align="center">No</td>
    <td width="151" class="tableHead" align="center">Date of Registration </td>
    <td width="176" class="tableHead" align="center">Customer ID </td>
    <td width="150" class="tableHead" align="center">Name</td>
    <td width="275" class="tableHead" align="center">Address</td>
    <td width="32" class="tableHead" align="center">Flag</td>
    <td width="35" class="tableHead" align="center">Details</td>
    <td width="38" class="tableHead" align="center">Edit</td>
    <td width="50" class="tableHead" align="center">Delete</td>
    </tr>

    <?

    // ambil isi dari file utama.php

    require("../koneksi/utama.php");


    // hubungkan ke database
    $link=open_connection();

    $sql = "select * from tbl_registrasi";

    $keyword = $_POST["keyword"];
    if($keyword!=""){
    $sql .= " where Nama_Pelanggan like '%$keyword%' or No_Pel like '%$keyword%' order by Id asc";
    }

    $rs = mysql_query($sql);
    $page = (($_GET["page"]=="") ? 1 : $_GET["page"]);
    $numrows = mysql_num_rows($rs);
    $pagesize = 5; //jumlah record per halaman
    $pagecount = ceil($numrows/$pagesize); //jumlah halaman
    $sql .= " limit " . (($page-1)*$pagesize) . " , " . $pagesize;
    $rs = mysql_query($sql);




    // jalankan perintah SQL
    $result=mysql_query($sql) or die ("Kesalahan pada perintah SQL");

    // putus hubungan dengan database
    mysql_close($link);
    //$i=0;

    // ambil isi masing-masing record
    while ($row = mysql_fetch_object($result))
    {
    // mengambil isi setiap kolom

    $id_no++;
    $var_id=$row->Id;
    $var_nopel=$row->No_Pel;
    $var_flag=$row->Flag;
    $var_nama=$row->Nama_Pelanggan;
    $var_alamat=$row->Alamat;
    $var_tgl=$row->Tgl_Register;
    $var_tlhr=$row->Tmpt_lhr;
    $var_tgllhr=$row->Tgl_lhr;
    $var_jkel=$row->J_kel;
    $var_pekerjaan=$row->Pekerjaan;
    $var_selectid=$row->IdCard;
    $var_noid=$row->No_Id;
    $var_email=$row->Email;
    $var_Uinput=$row->input_by;


    ?>
    <tr>
    <td align="center" class="tableCnt">&nbsp;<? echo($id_no); ?>&nbsp;</td>
    <td class="tableCnt">&nbsp;<? echo($var_tgl);?></td>
    <td class="tableCnt">&nbsp;<? echo($var_nopel); ?></td>
    <td class="tableCnt">&nbsp;<? echo($var_nama); ?></td>
    <td class="tableCnt">&nbsp;<? echo($var_alamat); ?></td>
    <td align="center" class="tableCnt"><? if($var_flag==0){
    echo("Non Aktif");
    } else {
    echo("Aktif");
    } ?></td>
    <td align="center" class="tableCnt">&nbsp;<a href="registrasi_detail.php?id=24&idno=<? echo($var_id); ?>&nopel=<? echo($var_nopel); ?>&flag=<? echo($var_flag); ?>&nama=<? echo($var_nama); ?>&almt=<? echo($var_alamat); ?>&tgl=<? echo($var_tgl); ?>&tlhr=<? echo($var_tlhr); ?>&tgllhr=<? echo($var_tgllhr); ?>&jkel=<? echo($var_jkel); ?>&pekerjaan=<? echo($var_pekerjaan); ?>&idcard=<? echo($var_selectid); ?>&noid=<? echo($var_noid); ?>&email=<? echo($var_email); ?>&input=<? echo($var_Uinput); ?>">&nbsp;Details&nbsp;</a></td>
    <td class="tableCnt"><a href="index.php?id=21&idno=<? echo($var_id); ?>&nopel=<? echo($var_nopel); ?>&nama=<? echo($var_nama); ?>&almt=<? echo($var_alamat); ?>">&nbsp;EDIT</a></td>
    <td class="tableCnt"><a href="javascript :confirmDelete('index.php?id=23&idno=<? echo($var_id);?>')">&nbsp;DELETE</a></td>
    </tr>
    <?
    }
    ?>
    <tr>
    <td colspan="9" align="center" class="tableCnt">&nbsp;
    <?
    //generate page navigation
    for($i=1;$i<=$pagecount;$i++)
    echo '<a href="?id=2&page='.$i.'">'.$i.'</a>&nbsp;&nbsp;';
    ?>
    </td>
    </tr>
    <tr><td> <a href="index.php?id=4" class="boxCek">New</a></td></tr>
    </table>


    </body>
    </html>
  • It works...udah jalan paging ama searchingnya...
    tapi ada satu lagi masalahnya...
    kenapa pas di searching yah...
    pagingnya masih ikutin data yang ada di database...?

    kenapa dia ga ikutin data yang udah ke search...
    misalnya nama Rini cuma 1 aja...
    kenapa pagingnya masih ada 7 ikutin data yang ada di databe ?

    bisakah...minta bantuannya tolong di cek scriptku :(

    =========================================

    <?
    session_start();
    if (!isset($_SESSION)) {
    header("Location: ../index.php");
    }
    ?>

    <html>
    <head>
    <title>View Registrasi</title>
    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
    <link href="css/dzt.css" rel="stylesheet" type="text/css">
    </head>
    <script>
    function confirmDelete(delUrl) {
    if (confirm("Are you sure you want to delete")) {
    document.location = delUrl;
    }
    }
    </script>


    <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

    <center>
    <font class="hsmf">View Customer Registration </font>
    </center>
    <br>
    <table width="339" height="33" border="0" align="center">
    <form name="search" method="get" action="" align="center">
    <tr>
    <td width="80"><b>Search :</b></td>
    <td width="124"><input name="keyword" type="text"></td>
    <td width="121"><input name="search" type="image" value="search" src="../images/arrow.gif" width="16" height="15"></td>
    </tr></form>
    </table>


    <table width="719" height="64" border="1" align="center">
    <tr>
    <td width="18" height="15" class="tableHead" align="center">No</td>
    <td width="151" class="tableHead" align="center">Date of Registration </td>
    <td width="176" class="tableHead" align="center">Customer ID </td>
    <td width="150" class="tableHead" align="center">Name</td>
    <td width="275" class="tableHead" align="center">Address</td>
    <td width="32" class="tableHead" align="center">Flag</td>
    <td width="35" class="tableHead" align="center">Details</td>
    <td width="38" class="tableHead" align="center">Edit</td>
    <td width="50" class="tableHead" align="center">Delete</td>
    </tr>

    <?
    // ambil isi dari file utama.php
    require("../koneksi/utama.php");

    // hubungkan ke database
    $link=open_connection();

    $query = "select * from tbl_registrasi";
    $query_jumlah = "select count(*) from tbl_registrasi";

    if(isset($_GET)){
    $keyword = urlencode($_GET);
    $query .= " where Nama_Pelanggan like '%$keyword%' order by Id";
    }

    $rs = mysql_query($query) or die (mysql_error());
    $perhalaman = 5;
    $halaman = isset($_GET["hal"]) ? $_GET["hal"] : "0";

    // hitung posisi awal data (offset)
    $awal = $halaman * $perhalaman;
    $id=$awal;

    $query .=" limit $awal,$perhalaman";
    $rs = mysql_query($query);

    // ambil jumlah total data
    $rs_jumlah = mysql_query($query_jumlah) or die(mysql_error());
    $r = mysql_fetch_row($rs_jumlah);

    // hitung total halaman
    $total_halaman = ceil($r[0] / $perhalaman);

    // bentuk halaman, di sini intinya

    $halaman_str = ""; // kosongkan variabel

    // jika berada pada halaman ketiga atau lebih, tampilkan link [pertama]
    if ($halaman > 1)
    //$halaman_str .= "<a href='?id=2&hal=0' title='Halaman pertama'>[First]</a> ";
    $halaman_str .= "<a href='?id=2&hal=0&keyword=".urlencode($keyword)."' title='Halaman pertama'>[First]</a> ";
    // jika berada pada halaman kedua atau lebih, tampilkan link [sebelumnya]
    if ($halaman > 0)
    {
    $hal = $halaman - 1;
    $halaman_str .= "<a href='?id=2&hal=$hal&keyword=".urlencode($keyword)."' title='Halaman sebelumnya'>[Previous]</a> ";
    }

    // ambil semua nomor halaman
    for ($i = 0; $i < $total_halaman; $i++)
    {
    $hal = $i + 1;
    if ($i == $halaman) // jika halaman aktif, tidak usah diberi link
    $halaman_str .= "$hal ";
    else
    $halaman_str .= "<a href='?id=2&hal=$i&keyword=".urlencode($keyword)."' title='Halaman $hal'>$hal</a> ";
    }

    // jika bukan berada pada halaman terakhir
    if ($halaman < ($total_halaman - 1))
    {
    $hal = $halaman + 1;
    $halaman_str .= "<a href='?id=2&hal=$hal&keyword=".urlencode($keyword)."' title='Halaman berikutnya'>[Next]</a> ";
    }

    // jika bukan pada 2 halaman terakhir
    if ($halaman < ($total_halaman - 2))
    {
    $hal = $total_halaman - 1;
    $halaman_str .= "<a href='?id=2&hal=$hal&keyword=".urlencode($keyword)."' title='Halaman terakhir'>[Last]</a> ";
    }


    // baca data halaman ini
    $rs = mysql_query($query) or die(mysql_error());


    // putus hubungan dengan database
    mysql_close($link);


    // ambil isi masing-masing record
    while ($row = mysql_fetch_object($rs))
    {
    // mengambil isi setiap kolom

    $id++;
    $var_id=$row->Id;
    $var_nopel=$row->No_Pel;
    $var_flag=$row->Flag;
    $var_nama=$row->Nama_Pelanggan;
    $var_alamat=$row->Alamat;
    $var_tgl=$row->Tgl_Register;
    $var_tlhr=$row->Tmpt_lhr;
    $var_tgllhr=$row->Tgl_lhr;
    $var_jkel=$row->J_kel;
    $var_pekerjaan=$row->Pekerjaan;
    $var_selectid=$row->IdCard;
    $var_noid=$row->No_Id;
    $var_email=$row->Email;
    $var_Uinput=$row->input_by;

    ?>
    <tr>
    <td align="center" class="tableCnt">&nbsp;<? echo($id); ?>&nbsp;</td>
    <td class="tableCnt">&nbsp;<? echo($var_tgl);?></td>
    <td class="tableCnt">&nbsp;<? echo($var_nopel); ?></td>
    <td class="tableCnt">&nbsp;<? echo($var_nama); ?></td>
    <td class="tableCnt">&nbsp;<? echo($var_alamat); ?></td>
    <td align="center" class="tableCnt"><? if($var_flag==0){
    echo("Non Aktif");
    } else {
    echo("Aktif");
    } ?></td>
    <td align="center" class="tableCnt">&nbsp;<a href="registrasi_detail.php?id=24&idno=<? echo($var_id); ?>&nopel=<? echo($var_nopel); ?>&flag=<? echo($var_flag); ?>&nama=<? echo($var_nama); ?>&almt=<? echo($var_alamat); ?>&tgl=<? echo($var_tgl); ?>&tlhr=<? echo($var_tlhr); ?>&tgllhr=<? echo($var_tgllhr); ?>&jkel=<? echo($var_jkel); ?>&pekerjaan=<? echo($var_pekerjaan); ?>&idcard=<? echo($var_selectid); ?>&noid=<? echo($var_noid); ?>&email=<? echo($var_email); ?>&input=<? echo($var_Uinput); ?>">&nbsp;Details&nbsp;</a></td>
    <td class="tableCnt"><a href="index.php?id=21&idno=<? echo($var_id); ?>&nopel=<? echo($var_nopel); ?>&nama=<? echo($var_nama); ?>&almt=<? echo($var_alamat); ?>">&nbsp;EDIT</a></td>
    <td class="tableCnt"><a href="javascript :confirmDelete('index.php?id=23&idno=<? echo($var_id);?>')">&nbsp;DELETE</a></td>
    </tr>
    <?
    }
    ?>
    <tr>
    <td colspan="9" align="center" class="tableCnt">&nbsp;
    <?
    echo "$halaman_str";
    ?>
    </td>
    </tr>
    <tr><td> <a href="index.php?id=4" class="boxCek">New</a></td></tr>
    </table>


    </body>
    </html>
  • Ya salahnya disini

    $query = "select * from tbl_registrasi";
    $query_jumlah = "select count(*) from tbl_registrasi";

    if(isset($_GET)){
    $keyword = urlencode($_GET);
    $query .= " where Nama_Pelanggan like '%$keyword%' order by Id";
    }

    Seharusnya

    $query = "select * from tbl_registrasi";

    if(isset($_GET)){
    $keyword = urlencode($_GET);
    $query .= " where Nama_Pelanggan like '%$keyword%'";
    }
    $qruery.=" order by Id";
    $rs = mysql_query($query) or die(mysql_error());
    $query_jumlah=mysql_num_rows($rs);
  • Originally posted by Goku
    Maksudnya si Rini cuma 1 data. Lalu saat ketik search muncul smapai halaman 7?

    betul...mas goku...kenapa gitu ?
  • Maksudnya si Rini cuma 1 data. Lalu saat ketik search muncul smapai halaman 7?
  • Originally posted by Goku
    Ya salahnya disini

    $query = "select * from tbl_registrasi";
    $query_jumlah = "select count(*) from tbl_registrasi";

    if(isset($_GET)){
    $keyword = urlencode($_GET);
    $query .= " where Nama_Pelanggan like '%$keyword%' order by Id";
    }

    Seharusnya

    $query = "select * from tbl_registrasi";

    if(isset($_GET)){
    $keyword = urlencode($_GET);
    $query .= " where Nama_Pelanggan like '%$keyword%'";
    }
    $qruery.=" order by Id";
    $rs = mysql_query($query) or die(mysql_error());
    $query_jumlah=mysql_num_rows($rs);

    $query = "select * from tbl_registrasi";
    $query_jumlah = "select count(*) from tbl_registrasi";

    if(isset($_GET)){
    $keyword = urlencode($_GET);
    $query .= " where Nama_Pelanggan like '%$keyword%'";
    }

    $query .= " order by Id";
    $rs = mysql_query($query) or die (mysql_error());

    $perhalaman = 5;
    $halaman = isset($_GET["hal"]) ? $_GET["hal"] : "0";

    // hitung posisi awal data (offset)
    $awal = $halaman * $perhalaman;
    $id=$awal;

    $query .=" limit " . ($awal) .",". $perhalaman;
    $rs = mysql_query($query);

    // ambil jumlah total data
    $rs_jumlah = mysql_query($query_jumlah) or die(mysql_error());
    $r = mysql_fetch_row($rs_jumlah);

    // hitung total halaman
    $total_halaman = ceil($r[0] / $perhalaman);

    ========================================

    kalo ikutin yg mas goku...error jadinya...gini errornya :

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '32' at line 1
  • Coba print querynya di baris yang error tadi ...
  • Originally posted by Goku
    Coba print querynya di baris yang error tadi ...

    Hoho...Terimakasih semuanya atas bantuannya...
    Akhirnya sudah jalan...:cool:
    Hasil terakhir nih....script punyaku ;)

    =======================================

    $query = "select * from tbl_registrasi";

    if(isset($_GET)){
    $keyword = urlencode($_GET);
    $query .= " where Nama_Pelanggan like '%$keyword%' OR No_Pel like '%$keyword%'";
    }
    $query .= " order by Id";
    $rs = mysql_query($query) or die (mysql_error());
    $numrows = mysql_num_rows($rs);

    $perhalaman = 5;
    $halaman = isset($_GET["hal"]) ? $_GET["hal"] : "0";

    // hitung posisi awal data (offset)
    $awal = $halaman * $perhalaman;
    $id=$awal;

    $query .=" limit " . $awal .",". $perhalaman;
    $rs = mysql_query($query);

    // hitung total halaman
    $total_halaman = ceil($numrows/$perhalaman);
  • Ya jelas lah

    $sql = "SELECT COUNT(*) FROM tbl_pegawai";
    $result = mysql_query($sql) or trigger_error('Error, query failed');
    $r = mysql_fetch_row($result);
    $numrows = $r[0];

    // number of rows to show per page
    $rowsperpage = 5;
    // find out total pages
    $totalpages = ceil($numrows / $rowsperpage);

    Total pagenya masih tanpa where di searchnya.
  • paging ini aku baru bikin kayak google mas goku...
    ini scriptnya dan kasusnya adalah...
    searching berhasil ditampilkan akan tetapi dia masih memunculkan paging yg ada di semua record...

    ==============================================

    <!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>View Gaji</title>
    <link href="../css/dzt.css" type="text/css" rel="stylesheet" />
    </head>

    <body>
    <table width="228" height="33" border="0" align="RIGHT">
    <form action="" method="get" name="search" id="search" align="center" >
    <input type="hidden" name="id" value="<? echo $_GET ;?>" />
    <tr>
    <td width="70"><b>Searching</b></td>
    <td width="124"><input name="keyword" type="text" /></td>
    <td width="20"><input name="search" type="image" value="search" src="../images/arrow.gif" width="16" height="15" /></td>
    </tr>
    </form>
    </table>
    <br /><br /><br />
         <a href="view_gaji.php" class="none">Show All</a>     <a href="view_rekap.php" tppabs="view_gaji.php" target="_blank" onclick="window.open('view_rekap.php'/*tpa=view_rekap.php*/,'win2','status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no'); return false;" title="View Rekap" class="none">View Rekap</a>
    <br />
    <br />
    <table width="1249" height="96" border="1" align="left">
    <tr>
    <td width="32" align="center" class="tableHead">No</td>
    <td width="217" align="center" class="tableHead">Nama</td>
    <td width="83" align="center" class="tableHead">NIP</td>
    <td width="76" align="center" class="tableHead">Tanggal Lahir</td>
    <td width="74" align="center" class="tableHead">Pendidikan</td>
    <td width="86" align="center" class="tableHead">Kelas Jabatan </td>
    <td width="103" align="center" class="tableHead">Jabatan</td>
    <td width="314" align="center" class="tableHead">Unit Kerja </td>
    <td width="78" align="center" class="tableHead">Gaji Pokok </td>
    <td width="122" align="center" class="tableHead">Aksi</td>
    </tr>

    <?
    // database connection info
    require("../koneksi/utama.php");
    $link=open_connection();

    // find out how many rows are in the table
    $sql = "SELECT COUNT(*) FROM tbl_pegawai";
    $result = mysql_query($sql) or trigger_error('Error, query failed');
    $r = mysql_fetch_row($result);
    $numrows = $r[0];

    // number of rows to show per page
    $rowsperpage = 5;
    // find out total pages
    $totalpages = ceil($numrows / $rowsperpage);

    // get the current page or set a default
    if (isset($_GET) && is_numeric($_GET)) {
    // cast var as int
    $currentpage = (int) $_GET;
    } else {
    // default page num
    $currentpage = 1;
    } // end if

    // if current page is greater than total pages...
    if ($currentpage > $totalpages) {
    // set current page to last page
    $currentpage = $totalpages;
    } // end if
    // if current page is less than first page...
    if ($currentpage < 1) {
    // set current page to first page
    $currentpage = 1;
    } // end if

    // the offset of the list, based on current page
    $offset = ($currentpage - 1) * $rowsperpage;


    // hitung posisi awal data (offset)
    $no=$offset;

    $sql = "SELECT * FROM tbl_pegawai
    LEFT JOIN tbl_jabatan ON tbl_pegawai.Kls_jabatan = tbl_jabatan.Kls_jabatan
    LEFT JOIN tbl_unitkerja ON tbl_pegawai.Kd_unitKerja = tbl_unitkerja.Kd_unitKerja";
    $rs = mysql_query($sql) or trigger_error('Error, query failed');

    $keyword = $_POST["keyword"];
    if(isset($_GET)){
    $keyword = urlencode($_GET);
    $sql .= " where Nama like '%$keyword%' or NIP like '%$keyword%' or Unit_Kerja like '%$keyword%'";
    }
    $sql .= " order by Id";
    $rs = mysql_query($sql) or die (mysql_error());
    $numrows = mysql_num_rows($rs);
    $sql .=" limit " . $offset .",". $rowsperpage;
    $rs = mysql_query($sql) or die (mysql_error());
    mysql_close($link);
    while ($row = mysql_fetch_object($rs))
    {
    $var_id=$row->Id;
    $nip=$row->NIP;
    $name=$row->Nama;
    $tgl_lhr=$row->Tgl_Lhr;
    $pend=$row->Pendidikan;
    $kls=$row->Kls_jabatan;
    $jabatan=$row->Deskripsi;
    $gapok=$row->GAPOK;
    $unit=$row->Unit_Kerja;
    $no++;
    ?>
    <tr>
    <td class="tableCnt" align="center"><? echo("$no");?> </td>
    <td class="tableCnt"> <? echo("$name");?> </td>
    <td class="tableCnt"> <? echo("$nip");?> </td>
    <td class="tableCnt"> <? echo("$tgl_lhr");?> </td>
    <td class="tableCnt"> <? echo("$pend");?> </td>
    <td class="tableCnt"> <? echo("$kls");?> </td>
    <td class="tableCnt"> <? echo("$jabatan");?> </td>
    <td class="tableCnt"> <? echo("$unit");?> </td>
    <td class="tableCnt"> <? echo("$gapok");?> </td>
    <td class="tableCnt"> <a href="print_gaji.php?sid=1&idno=<? echo($var_id); ?>&nama=<? echo($name); ?>&nip=<? echo($nip); ?>&tgl_lhr=<? echo($tgl_lhr);?>&pend=<? echo($pend);?>&kls=<? echo($kls);?>&jabatan=<? echo($jabatan);?>&unit=<? echo($unit);?>&gapok=<? echo($gapok);?>" class="none">Kupon Gaji</a> | <a href="edit_gaji.php?sid=2&idno=<? echo($var_id); ?>&nama=<? echo($name); ?>&nip=<? echo($nip); ?>&tgl_lhr=<? echo($tgl_lhr);?>&pend=<? echo($pend);?>&kls=<? echo($kls);?>&jabatan=<? echo($jabatan);?>&unit=<? echo($unit);?>&gapok=<? echo($gapok);?>" class="none">Edit</a></td>
    </tr>
    <?
    }
    ?>
    <tr>
    <td colspan="10" align="center" class="tableCnt"> 
    <?
    /****** build the pagination links ******/
    // range of num links to show
    $range = 3;

    // if not on page 1, don't show back links
    if ($currentpage > 1) {
    // show << link to go back to page 1
    echo " <a href='?id=2&currentpage=1&keyword=".urlencode($keyword)."'>[First Page]</a> ";
    // get previous page num
    $prevpage = $currentpage - 1;
    // show < link to go back to 1 page
    echo " <a href='?id=2&currentpage=$prevpage&keyword=".urlencode($keyword)."'>[Prev]</a> ";
    } // end if

    // loop to show links to range of pages around current page
    for ($x = (($currentpage - $range) - 1); $x < (($currentpage + $range) + 1); $x++) {
    // if it's a valid page number...
    if (($x > 0) && ($x <= $totalpages)) {
    // if we're on current page...
    if ($x == $currentpage) {
    // 'highlight' it but don't make a link
    echo " [<b>$x</b>] ";
    // if not current page...
    } else {
    // make it a link
    echo " <a href='?id=2&currentpage=$x&keyword=".urlencode($keyword)."'>$x</a> ";
    } // end else
    } // end if
    } // end for

    // if not on last page, show forward and last page links
    if ($currentpage != $totalpages) {
    // get next page
    $nextpage = $currentpage + 1;
    // echo forward link for next page
    echo " <a href='?id=2&currentpage=$nextpage&keyword=".urlencode($keyword)."'>[Next]</a> ";
    // echo forward link for lastpage
    echo " <a href='?id=2&currentpage=$totalpages&keyword=".urlencode($keyword)."'>[Last Page]</a> ";
    } // end if
    /****** end build pagination links ******/

    ?>
    </td>
    </tr>
    </table>
    </body>
    </html>
  • Iya iyalah...
  • Originally posted by Goku
    Iya iyalah...

    masa ya iya donk... :D
    ok...saya coba dulu mas ;)
  • Originally posted by Goku
    Ya jelas lah

    $sql = "SELECT COUNT(*) FROM tbl_pegawai";
    $result = mysql_query($sql) or trigger_error('Error, query failed');
    $r = mysql_fetch_row($result);
    $numrows = $r[0];

    // number of rows to show per page
    $rowsperpage = 5;
    // find out total pages
    $totalpages = ceil($numrows / $rowsperpage);

    Total pagenya masih tanpa where di searchnya.

    harusnya ditambahin where totalpages gitu ?
    gimana maksudnya...mas ?
    maklum masih baru belajar :)
Sign In or Register to comment.