<script type="text/javascript" src="js/jquery-1.2.3.pack.js"></script>
<script type="text/javascript" src="js/jquery.validate.pack.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#formnilai").validate({
messages: {
email: {
required: "E-mail harus diisi",
email: "Masukkan E-mail yang valid"
}
},
errorPlacement: function(error, element) {
error.appendTo(element.parent("td"));
}
});
})
</script>
<style type="text/css">
* { font: 11px Verdana, sans-serif; }
h4 { font-size: 18px; }
input { padding: 3px; border: 1px solid #999; }
input.error, select.error { border: 1px solid red; }
label.error { color:red; margin-left: 10px; }
td { padding: 5px; }
</style>
<?php
if($_POST[Update])
{
mysql_connect("localhost", "root", "");
mysql_select_db("dbdinamis");
// membaca jumlah (n) dari submit.php
$Siswa = $_POST[n];
$mapel = $_POST[matapelalajaran];
// proses looping untuk membaca nilai serta menjalankan query update
for ($i=1; $i<=$Siswa; $i++)
{
// membaca nim ke-i, i = 1, 2, 3, ..., n
$nis = $_POST[siswa.$i];
// membaca nilai ke-i, i = 1, 2, 3, ..., n
$nilai = $_POST[nilaiMID.$i];
$nilai1 = $_POST[nilaiUAS.$i];
$ubah=mysql_query("UPDATE nilai SET nilaiMID = '$nilai', nilaiUAS='$nilai1' WHERE nis='$nis' AND kodematapelajaran = '$mapel'");
}
echo "<script language='javascript'>alert('Data Telah di Update');</script>";
}
?>
<form id="form1" name="form1" method="post" action="">
<table align="center" width="80%" border="0">
<tr>
<td colspan="2" align="center">Entry data Nilai</td>
</tr>
<tr>
<td colspan="2" bgcolor="#006633"> </td>
</tr>
<tr>
<td>Pilih Matapelajaran :</td>
<td><select name="matapelajaran">
<option value="PILIH">PILIHAN</option>
<?php
// query untuk menampilkan semua matakuliah dari tabel 'mk'
$query = "SELECT * FROM matapelajaran";
$hasil = mysql_query($query);
while ($data = mysql_fetch_array($hasil))
{
echo "<option value='".$data['kodematapelajaran']."'>".$data['namamatapelajaran']."</option>";
}
?>
<input type="submit" value="Submit" name="submit" />
</select></td>
</tr>
</table>
</form>
<?php if ($_POST[submit]){?>
<form method="post" action="">
<table align="center" width="80%" border="0">
<tr>
<td colspan="5" align="center">Update Nilai Siswa</td>
</tr>
<tr>
<td colspan="5" style="border-bottom:1px solid #000;"><hr /></td>
</tr>
<tr>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;border-left:1px solid #000">No</td>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;">NISN</td>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;">Nama Siswa</td>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;">Nilai MID</td>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;">NIlai UAS</td>
</tr>
<?php
// membaca kode matakuliah yang disubmit dari formnilai.php
$idmapel = $_POST[matapelajaran];
include("../library/koneksi.php");
$query1 = mysql_query("SELECT nilai.nis, nilai.kodematapelajaran, nilai.nilaiMID, nilai.nilaiUAS, siswa.namasiswa
FROM nilai,siswa
WHERE nilai.nis=siswa.nis AND kodematapelajaran = '".$_POST[matapelajaran]."'")or die ("Query failed with error: ".mysql_error());
$i = 1;
while($data = mysql_fetch_array($query1)){
?>
<tr>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;border-left:1px solid #000"><? echo $i; ?></td>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;"><? echo $data[nis]; ?><input type='hidden' name="siswa" value="<? echo $data[nis]; ?>" /></td>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;"><? echo $data[namasiswa]; ?></td>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;"><input type="text" size='5' name="nilaiMID" id="nilaiMID" value="<? echo $data[nilaiMID]; ?>" /></td>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;"><input type="text" size='5' name="nilaiUAS" id="nilaiUAS" value="<? echo $data[nilaiUAS]; ?>" /></td>
</tr>
<? $i++; $jumSiswa = $i-1; } ?>
<tr>
<td><input type="text" name="n" value="<?php echo $jumSiswa ?>" /></td>
<td><input type="text" name="matapelajaran" value="<?php echo $idmapel;?>"></td>
<td colspan="2" align="center"><input type="submit" value="Update" name="Update" id="Update" /></td>
<td> </td>
</tr>
</table>
</form>
<? }?>
<script type="text/javascript" src="js/jquery-1.2.3.pack.js"></script>
<script type="text/javascript" src="js/jquery.validate.pack.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#formnilai").validate({
messages: {
email: {
required: "E-mail harus diisi",
email: "Masukkan E-mail yang valid"
}
},
errorPlacement: function(error, element) {
error.appendTo(element.parent("td"));
}
});
})
</script>
<style type="text/css">
* { font: 11px Verdana, sans-serif; }
h4 { font-size: 18px; }
input { padding: 3px; border: 1px solid #999; }
input.error, select.error { border: 1px solid red; }
label.error { color:red; margin-left: 10px; }
td { padding: 5px; }
</style>
<?php
if($_POST[Update])
{
mysql_connect("localhost", "root", "");
mysql_select_db("dbdinamis");
$mapel = $_POST['matapelajaran'];
// proses looping untuk membaca nilai serta menjalankan query update
foreach($_POST['siswa'] as $i => $nis) {
$nilai = $_POST['nilaiMID'][$i];
$nilai1 = $_POST['nilaiUAS'][$i];
$ubah=mysql_query("UPDATE nilai SET nilaiMID = '$nilai', nilaiUAS='$nilai1' WHERE nis='$nis' AND kodematapelajaran = '$mapel'");
}
echo "<script language='javascript'>alert('Data Telah di Update');</script>";
}
?>
<form id="form1" name="form1" method="post" action="">
<table align="center" width="80%" border="0">
<tr>
<td colspan="2" align="center">Entry data Nilai</td>
</tr>
<tr>
<td colspan="2" bgcolor="#006633"> </td>
</tr>
<tr>
<td>Pilih Matapelajaran :</td>
<td><select name="matapelajaran">
<option value="PILIH">PILIHAN</option>
<?php
// query untuk menampilkan semua matakuliah dari tabel 'mk'
$query = "SELECT * FROM matapelajaran";
$hasil = mysql_query($query);
while ($data = mysql_fetch_array($hasil))
{
echo "<option value='".$data['kodematapelajaran']."'>".$data['namamatapelajaran']."</option>";
}
?>
<input type="submit" value="Submit" name="submit" />
</select></td>
</tr>
</table>
</form>
<?php if ($_POST[submit]){?>
<form method="post" action="">
<table align="center" width="80%" border="0">
<tr>
<td colspan="5" align="center">Update Nilai Siswa</td>
</tr>
<tr>
<td colspan="5" style="border-bottom:1px solid #000;"><hr /></td>
</tr>
<tr>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;border-left:1px solid #000">No</td>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;">NISN</td>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;">Nama Siswa</td>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;">Nilai MID</td>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;">NIlai UAS</td>
</tr>
<?php
// membaca kode matakuliah yang disubmit dari formnilai.php
$idmapel = $_POST[matapelajaran];
include("../library/koneksi.php");
$query1 = mysql_query("SELECT nilai.nis, nilai.kodematapelajaran, nilai.nilaiMID, nilai.nilaiUAS, siswa.namasiswa
FROM nilai,siswa
WHERE nilai.nis=siswa.nis AND kodematapelajaran = '".$_POST[matapelajaran]."'")or die ("Query failed with error: ".mysql_error());
$i = 1;
while($data = mysql_fetch_array($query1)){
?>
<tr>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;border-left:1px solid #000"><? echo $i; ?></td>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;"><? echo $data[nis]; ?><input type='hidden' name="siswa[<? echo $i; ?>]" value="<? echo $data[nis]; ?>" /></td>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;"><? echo $data[namasiswa]; ?></td>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;"><input type="text" size='5' name="nilaiMID[<? echo $i; ?>]" id="nilaiMID" value="<? echo $data[nilaiMID]; ?>" /></td>
<td align="center" style="border-bottom:1px solid #000;border-right:1px solid #000;"><input type="text" size='5' name="nilaiUAS[<? echo $i; ?>]" id="nilaiUAS" value="<? echo $data[nilaiUAS]; ?>" /></td>
</tr>
<? $i++; $jumSiswa = $i-1; } ?>
<tr>
<td><input type="text" name="n" value="<?php echo $jumSiswa ?>" /></td>
<td><input type="text" name="matapelajaran" value="<?php echo $idmapel;?>"></td>
<td colspan="2" align="center"><input type="submit" value="Update" name="Update" id="Update" /></td>
<td> </td>
</tr>
</table>
</form>
<? }?>