Skip to main content

Membuat Combo berantai dalam satu database.

Simpan dalam dpl_data.php

<form method="POST" action="dkkn_tambah_simpan.php">

<tbody>
<tr> <input type="text" value="<?php echo $_GET['angkatan']; ?>" id="angkatan" name="angkatan" /></tr>

<tr><td>Nama DPL</td><td>:

<select name="nama" id="nama">
    <option value="">- Pilih Nama Dosen -</option>
   
    <!-- looping data nama -->
    <?php
    $sql_dosen="select * from tbdos";
    $q=$mysqli->query($sql_dosen);
    while($row_dosen=mysqli_fetch_array($q)){
   
    ?>
        <option value="<?php echo $row_dosen["nip"] ?>"><?php echo $row_dosen["nip"] ." - " . $row_dosen["nama"] ?></option>
   
    <?php
    }
    ?>
</select>

    &nbsp;&nbsp;&nbsp;<img src="loader.gif" width="10px" height="10px" id="imgLoad" style="display:none">
    <br>

<tr><td>NIK Dosen</td><td>: 
 <select name="kota" id="kota">
    <!-- hasil data dari cari_dosen.php akan ditampilkan disini ----------------------------------------------->
</select>


<tr><td>Type KKN</td><td>:
<select id="jenis" name ="jenis" />
<option value="Reguler 1" placeholder="Reguler I">Reguler 1
<option value="Reguler 2" placeholder="Reguler I">Reguler 2
<option value="Tematik" placeholder="Reguler I">Tematik
&nbsp;&nbsp;&nbsp;<img src="loader.gif" width="10px" height="10px" id="imgLoad" style="display:none">
</select>
</td></tr>

<tr><td>Tahun Akademik</td><td>:
<select id="tahun_akademik" name ="tahun_akademik" />
<?php include ("menu/listtakalender.php"); ?>
</select>
</td></tr>

<tr><td>Semester</td><td>:
<select  id="semester" name ="semester" />
<option placeholder="Pilih Semester">- Pilih Semester Ganjil/Genap
<option value="1" placeholder="">Ganjil
<option value="2" placeholder="">Genap
<option value="2" placeholder="">Antar Waktu
</select>
</td></tr>
</tbody>
</table>
<button type="submit" id="submit" class="btn btn-small btn-warning" ><a href="javascript:void(0)"></a><i class="icon-upload"></i> Simpan</button>

</form>



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


Paling bawah ditambah script:
<script>
 
    $("#nama").change(function(){
 
        // variabel dari nilai combo box nama
        var nik = $("#nama").val();
     
        // tampilkan image load
        $("#imgLoad").show("");
     
        // mengirim dan mengambil data
        $.ajax({
            type: "POST",
            dataType: "html",
            url: "menu/cari_dosen.php",
            data: "prov="+nik,
            success: function(msg){
             
                // jika tidak ada data
                if(msg == ''){
                    alert('Tidak ada data Dose ');
                }
             
                // jika dapat mengambil data,, tampilkan di combo box kota
                else{
                    $("#kota").html(msg);                                                    
                }
             
                // hilangkan image load
                $("#imgLoad").hide();
            }
        });  
    });
</script>

Simpan dalam menu/cari_dosen.php
<?php
// server info
$server = 'localhost';
$user = 'root';
$pass = '';
$db = 'simpeg';

// connect to the database
$mysqli = new mysqli($server, $user, $pass, $db);

// show errors (remove this line if on a live site)
mysqli_report(MYSQLI_REPORT_ERROR);

?>  
<?php

 
    $sql_dosen1="select * from tbdos where nip='".$_POST["prov"]."'";
    $q=$mysqli->query($sql_dosen1);
    while($row_dosen1=mysqli_fetch_array($q)){
 
    ?>
        <option value="<?php echo $row_dosen1["nip"] ?>"><?php echo $row_dosen1["nip"] ?></option><br>
 
    <?php
    }
    ?>

Comments

Popular posts from this blog

FPDF dengan CodeIgniter

Cetak Surat Keputusan Controller: <?php //File in controller named surat_keputusan.php defined('BASEPATH') OR exit('No direct script access allowed'); class Cetak_surat_keputusan extends CI_Controller { public function __construct()     {         parent::__construct();         $this->load->helper('url');         $this->load->database();                $this->db->select();         $this->db->from('surat.config_sk');                $query = $this->db->get();                 return $query->result();             } public function index() {      ...

Preview PDF di Modal Bootstrap dengan Ajax

//preview pdf in line function preview_surat_keputusan(no) { $('#form')[0].reset(); $('.form-group').removeClass('has-error'); $('.help-block').empty(); $.ajax({ url : "<?php echo site_url('surat_keputusan/ajax_preview/')?>/" + no, type: "GET", dataType: "JSON",     success: function(data)     {     //paramater yang akan ditampilkan di modal         $('[name="no"]').val(data.no);         $('[name="ns"]').val(data.ns);         $('[name="thts"]').val(data.thts);         $('[name="pdf"]').val("http://localhost/dosdm/document/sm/pdf/"+data.thts+"-SK-"+data.ns+".pdf");         var link_base =  "http://localhost/dosdm/document/sm/pdf/"+data.thts+"-SK-"+data.ns+".pdf" ;             $('#pdf_view').attr('src', link_base);      ...

Hack File .xlsb

For first you must create a backup copy of your Workbook!!! Then you have to rename the XLSB file with ZIP extension. Test.XLSB => Test.ZIP             Opening your ZIP file using a compression software (e.g. WinRar) I can see the content of the file, structured in folders Inside the folder xl you can find a binary file named vbaProject.bin. Extract it on your desktop and edit it using a text editor. In my case I used Notepad++. Using the Find function of your editor, you must search the text DPB And replace the DPB string with DPx Then save the vbaProject.bin and replace this file inside the .ZIP File, renaming then .ZIP file in XLSB. Reopening the XLSB file using Excel, you will get an error message: you have to answer Yes to this error message. Then  Save , Close and Reopen your XLSB file. Now, if you go to VBA Editor (ALT + F11), you ca...