删除行后返回上一页

时间:2015-02-28 16:59:15

标签: php mysql

<?php
include_once "library/inc.sesadmin.php";
include_once "library/inc.library.php";
include_once "mhsfunc.php";

$filterSQL  = "";


if(isset($_POST['btnSubmit'])) {
  $txtNim     = trim($_POST['txtNim']);
  $txtNama    = trim($_POST['txtNama']);
  $cmbProdi   = trim($_POST['cmbProdi']);
  $txtSmt     = trim($_POST['txtSmt']);
  $cmbSmt     = trim($_POST['cmbSmt']);

if($cmbSmt<>""){
$filterSQL = "WHERE khs.nim='$txtNim' AND khs.smt='$cmbSmt'";  
}else {
$filterSQL = "WHERE khs.nim='$txtNim'";  
}
} else {
$filterSQL = "WHERE khs.nim='zzz'";  
}

#tampilkan hasil isian di form
$dataNim      =isset($_POST['txtNim']) ? $_POST['txtNim'] : '';
$dataNama     =isset($_POST['txtNama']) ? $_POST['txtNama'] : '';
$dataProdi    =isset($_POST['cmbProdi']) ? $_POST['cmbProdi'] : '';
$dataSmtMhs   =isset($_POST['txtSmt']) ? $_POST['txtSmt'] : '';
$dataSmtKrs   =isset($_POST['cmbSmt']) ? $_POST['cmbSmt'] : '';


# FOR PAGING (PEMBAGIAN HALAMAN)
$baris      = 50;
$hal          = isset($_GET['hal']) ? $_GET['hal'] : 1;
$pageSql    = "SELECT * FROM khs $filterSQL";
$pageQry    = mysql_query($pageSql, $koneksidb) or die ("error paging:    ".mysql_error());
$jumlah     = mysql_num_rows($pageQry);
$maks         = ceil($jumlah/$baris);
$mulai      = $baris * ($hal-1); 
$jmlsks     = 0;
$jmlbobot   = 0;
$ipk        = 0;
?>
<table width="800" border="0" cellpadding="2" cellspacing="0" class="table-border">
<tr>
  <td colspan="3" align="right"><h1><b>DATA KRS MAHASISWA </b></h1></td>
</tr>
<tr>
  <td colspan="3">

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="form1" target="_self">
   <table class="table-list" width="1000" border="0" cellpadding="2" cellspacing="1" >

    <tr>
      <td colspan="3" style="font-size:20px; font-family:Cambria" bgcolor="#F5F5F5"><b>FILTER DATA</b></td>
    </tr>

    <tr>
      <td width="169"><b>NIM Mahasiswa</b></td>
      <td width="5"><b>:</b></td>
      <td width="260"><input name="txtNim" type="text" id="txtNim" value="<?php echo $dataNim; ?>" size="15" maxlength="12" /></td>
    </tr>

    <tr>
      <td><b>Nama Mahasiswa</b></td>
      <td><b>:</b></td>
      <td><input name="txtNama" type="text" id="txtNama" value="<?php echo $dataNama; ?>" size="40" maxlength="40" /></td>
    </tr>

    <tr>
      <td><b>Program Studi</b></td>
      <td><b>:</b></td>
      <td><select name="cmbProdi" id="cmbProdi">
          <option value="KOSONG">....</option>
          <?php
            $dataSql = "SELECT * FROM prodi ORDER BY kode";
            $dataQry = mysql_query($dataSql, $koneksidb) or die ("Gagal Query".mysql_error());
            while ($dataRow = mysql_fetch_array($dataQry)) {
              if ($dataRow['kode'] == $cmbProdi) {
              $cek = " selected";
            } else { $cek=""; }
              echo "<option value='$dataRow[kode]' $cek> [$dataRow[kode]] $dataRow[nama]</option>";
            }
          ?>
           </select>
      </td>
    </tr>

    <tr>
      <td><b>Semester Mahasiswa</b></td>
      <td><b>:</b></td>
      <td><input name="txtSmt" type="text" id="txtSmt" value="<?php echo $dataSmtMhs; ?>" size="3" maxlength="1" /></td>
    </tr>

    <tr>
      <td><b>Semester KRS</b></td>
      <td><b>:</b></td>
      <td><select name="cmbSmt" id="cmbSmt">
          <option value="">ALL</option>
          <?php
           $pilihan = array("1", "2", "3", "4", "5","6");
           foreach ($pilihan as $semester) {
              if ($dataSmtKrs==$semester) {
                    $cek="selected";
              } else { $cek = "";}
                echo "<option value='$semester' $cek>$semester</option>";
              }
          ?>
          </select>
      </td>
    </tr>

    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td><input name="btnSubmit" type="submit" value=" Submit" id="btnSubmit" /></td>
    </tr>

   </table>
</form>

<tr>
  <td colspan="3">&nbsp;</td>
</tr>

<tr>
  <td colspan="3">
  <table class="table-list" width="100%" border="0" cellspacing="1" cellpadding="2">

  <tr>
    <td colspan="5"><a href="?open=KRS-Add" target="_self"><img src="images/btn_add_data.png" height="30" border="0" /></a></td>
  </tr>

  <tr>
    <td width="28" align="center" bgcolor="#F5F5F5"><b>No</b></td>
    <td width="63" bgcolor="#F5F5F5"><b>NIM</b></td>
    <td width="53" bgcolor="#F5F5F5"><b>KDMK</b></td>
    <td width="368" bgcolor="#F5F5F5"><b>NAMA MK</b></td>
    <td width="35" bgcolor="#F5F5F5"><b>SMT</b></td>
    <td width="30" bgcolor="#F5F5F5"><b>SKS</b></td>
    <td width="26" bgcolor="#F5F5F5"><b>TM</b></td>
    <td width="21" bgcolor="#F5F5F5"><b>PR</b></td>
    <td width="19" bgcolor="#F5F5F5"><b>LP</b></td>
    <td width="252" bgcolor="#F5F5F5"><b>DOSEN (NIDN/NAMA)</b></td>
    <td align="center" bgcolor="#CCCCCC"><b>Tools</b></td>
</tr>
      <?php
        $mySql = "SELECT      khs.id_khs, khs.nim, khs.kdmk, khs.nmmk,  khs.smt, mtkul.sks, mtkul.tm, mtkul.pr, mtkul.lp,mtkul.nodos
                  FROM        khs
                  INNER JOIN  mtkul
                  ON          khs.tahun=mtkul.tahun AND khs.prodi=mtkul.prodi AND khs.smt=mtkul.smt AND khs.kdmk=mtkul.kode $filterSQL 
                  ORDER BY    khs.smt, khs.kdmk LIMIT $mulai, $baris";
        $myQry = mysql_query($mySql, $koneksidb)  or die ("Query salah : ".mysql_error());
        $nomor  = $mulai; 
        while ($myData = mysql_fetch_array($myQry)) {
          $nomor++;
          $nidn     = $myData['nodos'];
          $Kode     = $myData['id_khs'];
          $jmlsks   = $jmlsks+$myData['sks'];
          $qryDosen = "SELECT * from dosen WHERE nidn=$nidn";
          $qryCek   = mysql_query($qryDosen, $koneksidb) or die ("Eror Query".mysql_error()); 
          $myData2  = mysql_fetch_assoc($qryCek);
          if(mysql_num_rows($qryCek)>=1){
              $namaDosen=$myData2['nama'];
          } else {$namaDosen=$nidn;}
          // Gradasi warna baris
          if($nomor%2==1) { $warna="#FFFFFF"; } else {$warna="#F5F5F5";}
        ?>
  <tr bgcolor="<?php echo $warna; ?>">
    <td align="center"><?php echo $nomor; ?></td>
    <td><?php echo $myData['nim']; ?></td>
    <td><?php echo $myData['kdmk']; ?></td>
    <td><?php echo $myData['nmmk']; ?></td>
    <td align="center"><?php echo $myData['smt']; ?></td>
    <td align="center"><?php echo $myData['sks']; ?></td>
    <td><?php echo $myData['tm']; ?></td>
    <td><?php echo $myData['pr']; ?></td>
    <td><?php echo $myData['lp']; ?></td>
    <td><?php echo $namaDosen ?></td>
    <td width="56" align="center"><a href="?open=KRS-Delete&Kode=<?php echo  $Kode; ?>" target="_self" alt="Delete Data" onclick="return confirm('Are You Sure ...?')">Delete</a></td>

//here is the KRS-Delete.php
<?php
include_once "library/inc.sesadmin.php";

 // Get From URL
 if(empty($_GET['Kode'])){
   echo "<b>Data yang dihapus tidak ada</b>";
 }
 else {
    $Kode   = $_GET['Kode'];
$mySql = "DELETE FROM khs WHERE id_khs='$Kode'";
$myQry = mysql_query($mySql, $koneksidb) or die ("Eror hapus data".mysql_error());

if (mysql_affected_rows() > 0) {
    header('location: ' .$_GET['Kode']); 
    echo "<script type=\"text/javascript\">".
         "alert('Data Berhasil Di Hapus');".
         "</script>";

    echo "<meta http-equiv='refresh' content='0; url=?open=KRS-Data'>";

} else {
    echo "Data tidak ditemukan !! <br><br>";
}

我的问题是,当我成功删除一行时,我希望我的页面返回显示上一个显示的表,减去我已使用完全相同的页码删除的行。我需要解析和解析KRS-Delete.php

1 个答案:

答案 0 :(得分:0)

在构建涉及多个步骤的UI页面时,我更喜欢将所有步骤放在同一个PHP文件中。我从$foo = @$_GET['foo']; if ($foo) DoFoo();开始,看看这个调用是否需要执行“foo”步骤(例如执行DELETE)。在DoFoo()之后,我通常会进入主代码,它会显示与原始页面相同(或类似)的UI页面。

除了避免你提到的导航问题外,它还允许我在一个文件中包含此UI的“全部”内容。通常也有很多通用代码。