Mas saya mau tanya dong buat edit data yg menggunakan combobox dinamis dgn script dibawah ini.
fakultas sama jurusannya gag kepilih sesuai dgn data sebelumnya.
tabelny nya ada fakultas=>idFak,namaFakultas ; jur=>idJur, namaJurusan, idFak : mahasiswa=>ID,NPM,nama,idFak,idJur,tahun, dll.
<?php
include("koneksi.php");
$ID = $_GET['ID'];
if($_POST['btnsimpan'] == "Update")
{
$NPM = $_POST['NPM'];
$Nama = $_POST['Nama'];
$idFak= $_POST['fakultas'];
$idJur = $_POST['jur'];
$Tahun = $_POST['Tahun'];
$General_Test = $_POST['General_Test'];
$LRK = $_POST['LRK'];
$Kinerja_Mahasiswa = $_POST['Kinerja_Mahasiswa'];
$LPK = $_POST['LPK'];
$Pendadaran = $_POST['Pendadaran'];
$NA = $_POST['NA'];
$Nilai_Mutu = $_POST['Nilai_Mutu'];
if($ID != "" and $NPM != "" and $Nama != "" and $idFak != "" and $idJur != "" and $Tahun != "" and $General_Test != "" and $LRK != "" and $Kinerja_Mahasiswa != "" and $LPK != "" and $Pendadaran != "" and $NA != "" and $Nilai_Mutu != "")
{
$sql = "UPDATE mahasiswa SET NPM='NPM', Nama ='Nama', idFak = 'fakultas', idJur = 'jur',Tahun = 'Tahun', General_Test ='General_Test}', LRK ='LRK', Kinerja_Mahasiswa ='Kinerja_Mahasiswa', LPK ='LPK',Pendadaran='Pendadaran', NA ='NA', Nilai_Mutu ='Nilai_Mutu' WHERE ID = 'ID']}'";
mysql_query($sql);
if(mysql_errno() == 0)
{
echo"<script>alert('Data Berhasil Diupdate !');</script>";
$page = "Data.php";
echo "<meta http-equiv='refresh' content='0;url=$page'/>";
}else{
echo"<script>alert('Data Gagal Diupdate !');</script>";
}
}else{
echo"<script>alert('Data Harus Diisi Lengkap !');</script>";
}
}
$sqldata = "SELECT * FROM mahasiswa WHERE ID = '$ID'";
$result = mysql_query($sqldata);
if(mysql_num_rows($result) > 0)
{
while($data = mysql_fetch_array($result))
{
$NPM = $data['NPM'];
$Nama = $data['Nama'];
$idFak = $data['fakultas'];
$idJur = $data['jur'];
$Tahun = $data['Tahun'];
$General_Test = $data['General_Test'];
$LRK = $data['LRK'];
$Kinerja_Mahasiswa = $data['Kinerja_Mahasiswa'];
$LPK = $data['LPK'];
$Pendadaran = $data['Pendadaran'];
$NA = $data['NA'];
$Nilai_Mutu = $data['Nilai_Mutu'];
}
}
?>
<!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=utf-8" />
<title>Edit Data Nilai KKN Mahasiswa</title>
<script language="JavaScript" type="text/JavaScript">
function showjur()
{
<?php
// membaca semua fakultas
$query = "SELECT * FROM fakultas";
$hasil = mysql_query($query);
// membuat if untuk masing-masing pilihan fakultas beserta isi option untuk combobox kedua
while ($data = mysql_fetch_array($hasil))
{
$idFak = $data['idFak'];
// membuat IF untuk masing-masing fakultas
echo "if (document.demo.fakultas.value == \"".$idFak."\")";
echo "{";
// membuat option jurusan untuk masing-masing fakultas
$query2 = "SELECT * FROM jur WHERE idFak = $idFak";
$hasil2 = mysql_query($query2);
$content = "document.getElementById('jurusan').innerHTML = \"";
while ($data2 = mysql_fetch_array($hasil2))
{
$content .= "<option value='".$data2['idJur']."'>".$data2['namaJurusan']."</option>";
}
$content .= "\"";
echo $content;
echo "}\n";
}
?>
}
</script>
</head>
<body>
<table align="Left">
<tr>
<td width="439">
<fieldset>
<legend><font color="#000000"><b>[ Edit Data Nilai Mahasiswa ]</b></font></legend>
<form name="demo" method="post" action="edittampilan.php">
<table>
<tr>
<td width="107"><font color="#000000">NPM</font></td>
<td width="292">
<input type="text" name="NPM" value="<?php echo"$NPM"; ?>" />
</td>
</tr>
<tr>
<td><font color="#000000">Nama</font></td>
<td>
<input type="text" name="Nama" value="<?php echo"$Nama"; ?>"/>
</td>
</tr>
<tr>
<tr>
<td><font color="#000000">Fakultas</font></td>
<td>
<select name="fakultas" onchange="showjur()">
<option value="">- Pilih Fakultas -</option>
<?php
// query untuk menampilkan fakultas
$query = "SELECT * FROM fakultas";
$hasil = mysql_query($query);
while ($data = mysql_fetch_array($hasil))
{
$selected = '';
if($data['idFak'] == $ID){
$selected = 'selected="selected"';
}
echo '<option value="'.$data['idFak'].'" '.$selected.'>'.$data['namaFakultas'].'</option>';
}
?>
</select>
</td>
</tr>
<tr><td><font color="#000000">Jurusan</font></td>
<td>
<select name="jur" id="jurusan">
<option value="">- Pilih Jurusan -</option>
</select>
</td>
</tr>
<tr>
<td><font color="#000000">Tahun</font></td>
<td>
<select name="Tahun">
<option value="">- Pilih Tahun -</option>
<?php
$Tahun_skrng = date('Y');
$Tahun_mulai = $Tahun_skrng - 2;
$Tahun_akhir = $Tahun_skrng + 10;
for($th=$Tahun_mulai;$th<=$Tahun_akhir;$th++)
{
echo"<option value='$th' ";
if($Tahun == $th)
{
echo"selected='selected'";
}
echo">$th</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td><font color="#000000">General Test</font></td>
<td>
<input type="text" name="General_Test" value="<?php echo"$General_Test"; ?>"/>
</td>
</tr>
<tr>
<td><font color="#000000">LRK</font></td>
<td>
<input type="text" name="LRK" value="<?php echo"$LRK"; ?>"/>
</td>
</tr>
<tr>
<td><font color="#000000">Kinerja Mahasiswa</font></td>
<td>
<input type="text" name="Kinerja_Mahasiswa" value="<?php echo"$Kinerja_Mahasiswa"; ?>"/>
</td>
</tr>
<tr>
<td><font color="#000000">LPK</font></td>
<td>
<input type="text" name="LPK" value="<?php echo"$LPK"; ?>"/>
</td>
</tr>
<tr>
<td><font color="#000000">Pendadaran</font></td>
<td>
<input type="text" name="Pendadaran" value="<?php echo"$Pendadaran"; ?>"/>
</td>
</tr>
<tr>
<td><font color="#000000">NA</font></td>
<td>
<input type="text" name="NA" value="<?php echo"$NA"; ?>"/>
</td>
</tr>
<tr>
<td><font color="#000000">Nilai Mutu</font></td>
<td>
<input type="radio" name="Nilai_Mutu" value="A" <?php if($Nilai_Mutu == "A"){echo "checked='checked'";} ?>/><font color="#000000">A</font>
<input type="radio" name="Nilai_Mutu" value="B+" <?php if($Nilai_Mutu == "B+"){echo "checked='checked'";} ?>/><font color="#000000">B+</font>
<input type="radio" name="Nilai_Mutu" value="B" <?php if($Nilai_Mutu == "B"){echo "checked='checked'";} ?>/><font color="#000000">B</font>
<input type="radio" name="Nilai_Mutu" value="C+" <?php if($Nilai_Mutu == "C+"){echo "checked='checked'";} ?>/><font color="#000000">C+</font>
<input type="radio" name="Nilai_Mutu" value="C" <?php if($Nilai_Mutu == "C"){echo "checked='checked'";} ?>/><font color="#000000">C</font>
<input type="radio" name="Nilai_Mutu" value="D" <?php if($Nilai_Mutu == "D"){echo "checked='checked'";} ?>/><font color="#000000">D</font>
<input type="radio" name="Nilai_Mutu" value="E" <?php if($Nilai_Mutu == "E"){echo "checked='checked'";} ?>/><font color="#000000">E</font>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="submit" name="btnsimpan" value="Update" />
</td>
</tr>
</table>
</form>
</fieldset>
</td>
</tr>
</table>
</body>
</html>