0

I'm still new in web programming, I got trouble when get result form mysql. I'm using two parameter to get the data I wanted that sent to another file, Here is my code jQuery code:

<script type="text/javascript">
        $(document).ready(function(){
                  $('#tingkat').change(function(){
                    $('#unenroll').text("");
                      var thn_ajar = $("#thn_ajar").val();
                      var grade = $("#tingkat").val();
                      alert(grade); // check if there a value
                      alert(thn_ajar); // check if there a value
                        $.ajax({
                                  url     : "unenroll.php",
                                  type    : "get",
                                  data    : {"thn_ajar": thn_ajar, "grade": grade},
                                  success : function(data){
                                            $("#unenroll").html(data);
                                  },
                                  error   :
                                  function(xhr, teksStatus, kesalahan){
                                    $('#info').html('<b>Terjadi Kesalahan</b>');
                                  }
                        }); // end of $.ajax select unenroll
                  }); // end of $('#tingkat')
        }); //end of $(document)
    </script>>

This one to get the mysql data according parameter I input, I'm using PDO for access the data :

<?php
include"db_connect.php";

try{
      $kueri1 = $dt_bas->prepare("SELECT * FROM thn_ajaran ORDER BY tahun_ajaran DESC");
      $kueri1->execute();
}catch(PDOException $e){
  echo "Error".$e;
}

try {
      $kueri2 = $dt_bas->prepare("SELECT * FROM tingkat");
      $kueri2->execute();
} catch (PDOException $e) {
  echo "Error".$e;
}

?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
  <form method="get">
    <?php


     $thn_ajar = trim($_GET['thn_ajar']);
     $grade = trim($_GET['grade']);
    ?>

    <table>
  <?php


   $thn_ajar = trim($_GET['thn_ajar']);
   $grade = trim($_GET['grade']);
  ?>
  <thead>
            <th>N I S</th>
            <th>NAMA SISWA</th>
            <th>AKSI</th>
  </thead>
  <tbody>
  <?php
    include "db_connect.php";
    try{
                                      $kueri_siswa = $dt_bas->prepare("SELECT z.nis, z.nm_dpn FROM
                                                                                    (SELECT h.nis, h.nm_dpn, i.grade FROM siswa h
                                                                                    INNER JOIN tingkat i ON h.id_tingkat = i.id_tingkat
                                                                                    WHERE i.id_tingkat = :grade AND h.status_siswa ='AKTIF') z

                                                                                    LEFT JOIN
                                                                                    (SELECT d.nis FROM kelas a
                                                                                    INNER JOIN thn_ajaran b ON  a.id_thn_ajar = b.id_thn_ajar
                                                                                    INNER JOIN siswa_kelas c ON a.id_kelas = c.id_kelas
                                                                                    INNER JOIN siswa d ON d.nis = c.nis
                                                                                    INNER JOIN tingkat e ON e.id_tingkat = a.id_tingkat
                                                                                    WHERE b.tahun_ajaran = :thn_ajar AND e.id_tingkat =:grade2) l

                                                                                    ON z.nis = l.nis
                                                                                    WHERE
                                                                                        l.nis IS NULL");
                                        $kueri_siswa->bindParam(':grade', $grade);
                                        $kueri_siswa->bindParam(':thn_ajar', $thn_ajar);
                                        $kueri_siswa->bindParam(':grade2', $grade);
                                        $kueri_siswa->execute();
                              }catch(PDOException $le){
                                    echo "Error : $le";
                              }
      while ($row = $kueri_siswa->fetch(PDO::FETCH_ASSOC)) {

                         ?>
                                Tabel Row Start ASC
                        <tr>
                          <td><?php echo $row["nis"];?></td>

                          <td><?php echo $row["nm_dpn"];?></td>

                          <td>
                            <a href="#">Ubah<a/>
                            <a href="#">Detail</a>
                          </td>
                        </tr>
  <?php
  }
      ?>
  </tbody>
</table>
  </form>

</body>
<html>

When I check my console, there is no error, but the data I want to show don't show Thank's for your advice and time.

christ_tp
  • 13
  • 6

1 Answers1

-1

please change the syn text of data parameter in ajax so remove double quotes from variable names.

  data    : {thn_ajar: thn_ajar, grade: grade},
Bhavin Thummar
  • 1,255
  • 1
  • 12
  • 29
  • Thanks, for your advice but it still doesn't work. I'm just curious if data I the parameter I send is read as array. – christ_tp Jun 19 '17 at 05:35
  • now are you getting the get data in unenroll.php file or not? – Bhavin Thummar Jun 19 '17 at 05:49
  • no, I got nothing from unenroll.php but In my console just like this, XHR finished loading: GET "http://localhost/project/php/admin/unenroll.php?thn_ajar=53&grade=SMPDB002" – christ_tp Jun 19 '17 at 05:54
  • if you echo this thing $thn_ajar = trim($_GET['thn_ajar']); $grade = trim($_GET['grade']); then you get this values from ajax . – Bhavin Thummar Jun 19 '17 at 05:57
  • thank's, I've fixed the problem :) (y). May I ask U something? – christ_tp Jun 19 '17 at 07:52
  • I make improve from my code I post, then I got this from my console, [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/. – christ_tp Jun 19 '17 at 07:58
  • What, I'm trying to do is : 1. When I select my 1st and 2nd, I will get data from student table whose don't have class and I gonna get data for my 3rd drop down list (This problem is solved). 2. When I change value in my 3rd drop down list, it will show another table for student whose have class (The problem is here). The warning my console, show me is above of this explanation. – christ_tp Jun 19 '17 at 08:06
  • https://stackoverflow.com/questions/27736186/jquery-has-deprecated-synchronous-xmlhttprequest/27736383#27736383 please check above link may be it become useful for you. – Bhavin Thummar Jun 19 '17 at 08:38
  • Thank you, you're really help me... I wonder if I cant keep touch with you – christ_tp Jun 19 '17 at 09:19