ya mas makasi, mau tanya lagi nih mas. nim, kodemakul bisa input tapi semester'ya gak bisa...mohon koreksinya gan
modkrs.php
<?
session_start();
include "config/koneksi.php";
$bln_sekarang=date("m");
$operator = '!=';
if($bln_sekarang < 6){ //genap
$operator = '=';
}
$sql =mysql_query ("select * from makul where SEMES % 2 $operator 0 order by SEMES asc");
while($k=mysql_fetch_array($sql)){
$kode[]=$k['KDMKM'];
$nama[]=$k['NAKMK'];
$sks[] = $k['SKSMK'];
$semester[]=$k['SEMES'];
}
?>
<html>
<head>
<title>Check Box</title>
<script>
<?php
echo "var jumlah = ".count($kode).";\n";
echo "var sks = new Array();\n";
//mengambil sks matakuliah dan memasukkan ke array javascript
for($j=0;$j<count($kode);$j++){
echo "sks['".$kode[$j]."'] = ".$sks[$j].";\n";
}
?>
function hitungtotal(){
jum = 0;
for(i=0;i<jumlah;i++){
id = "mk"+i;
td1 = "k1"+i;
td2 = "k2"+i;
td3 = "k3"+i;
td4 = "k4"+i;
if(document.getElementById(id).checked){
kode = document.getElementById(id).value
jum = jum + sks[kode];
//untuk mengubah warna latar tabel apabila diceklist
document.getElementById(td1).style.backgroundColor = "white";
document.getElementById(td2).style.backgroundColor = "white";
document.getElementById(td3).style.backgroundColor = "white";
document.getElementById(td4).style.backgroundColor = "white";
}else {
document.getElementById(td1).style.backgroundColor = "white";
document.getElementById(td2).style.backgroundColor = "white";
document.getElementById(td3).style.backgroundColor = "white";
document.getElementById(td4).style.backgroundColor = "white";
}
}
//menampilkan total jumlah SKS yang diambil
document.getElementById("jsks").innerHTML = jum;
}
</script>
</head>
<body>
<?php
$query="select * from mhs where NIMHS='".$_SESSION['NIMHS']."'";
$result=mysql_query($query);
$data=mysql_fetch_array($result);
// cari tahun sekaran dan bulan sekarang
$bln_sekarang=date("m");
//jika bukan sekarang lebih dari bukan ke 5 dan kurang dari bulan ke 13
if($bln_sekarang >05 and $bln_sekarang<=12){
$thn_sekarang .="2";
$sem="Gasal";
}else{
$thn_sekarang .="1";
$sem="Genap";
}
echo"<table width=\"400\" cellspacing=5 border=\"0\"><tr><td rowspan=\"4\" valign=\"top\" align=\"justify\">
<tr><td>Nama</td><td>: $data[NMMHS]</td>";
echo "<td>NIM</td><td>: $data[NIMHS]</td></tr>";
echo"<tr><td>Semester</td><td>: $sem</td>
<td>Program Studi</td><td>: $data[KDPRODI]</td>
</tr>";
$ip = mysql_query("select * from nilai WHERE NIMHS = '$_SESSION[NIMHS]'");
while($l = mysql_fetch_array($ip)){
$ipnya = $l['IPS'];
if($ipnya>=3){
$sks_dptdiambil="24 sks";
}
elseif($ipnya>=2.5 and $ipnya<3){
$sks_dptdiambil="21 sks";
}
elseif($ipnya>=2 and $ipnya<2.5){
$sks_dptdiambil="18 sks";
}
elseif($ipnya>=1.5 and $ipnya<2){
$sks_dptdiambil="15 sks";
}
else{
$sks_dptdiambil="12 sks";
}
echo "<tr>";
echo "<td >Ip Sebelumnya</td><td>: $ipnya</td>";
echo "<td >Jumlah SKS Y.A.D</td><td>: $sks_dptdiambil";
echo "</td></tr></table>";
}
?>
<p><form name="formkrs" method="POST" action="index1.php?hal=inputkrs">
<table border=1 width=400 style="border-collapse:collapse" bordercolor="#999999">
<tr><td><b>Kode</b></td><td><b>Nama Mata Kuliah</b></td>
<td align="center"><b>SKS</b></td><td align="center"><b>SEMESTER</b></td>
<td align="center"><b>Ambil</b></td></tr>
<?php
//menampilkan matakuliah ke dalam tabel
for($i=0;$i<count($kode);$i++){
echo "<tr><td id=k1$i>".$kode[$i]."</td>";
echo "<td id=k2$i>".$nama[$i]."</td>";
echo "<td align='center' id=k3$i>".$sks[$i]."</td>";
echo "<td align='center' id=k3$i>".$semester[$i]."</td>";
echo "<td align='center' id=k4$i><input type=checkbox name=mk[] onclick=hitungtotal()
value=".$kode[$i]." id=mk".$i."></tr>";
}
?>
<tr><td colspan=4>JUMLAH YANG DIAMBIL</td><td align="center"><span id=jsks></span></td></tr>
</table>
<input name="kirim" type="submit" value="Kirim KRS">
</form>
</body>
</html>
inputkrs.php
<?php
session_start();
include "config/koneksi.php";
$tahun= date("Y");
$cek = mysql_query("SELECT * FROM krs1 WHERE NIMHS='$NIMHS' and semester='$semester' and tahun='$tahun' ");
$batas = mysql_query("SELECT COUNT(KDMKM) FROM makul");
if(mysql_num_rows($cek) > 0 ){
die("Anda sudah melakukan pengisian KRS pada semester ini");
}
foreach($_POST['mk'] as $value){
mysql_query("insert into krs1 (NIMHS,kodekuliah,semester,tahun) values ('$NIMHS','$value','$semester','$tahun')");
}
echo"NIM : $NIMHS<br>";
echo"Semester : $semester<br>";
echo"Tahun : $tahun<br>";
//Menampilkan kembali yang sudah diambil
?>
Berikut KRS yang anda ambil :
<table border=1 width=400 style="border-collapse:collapse" bordercolor="#999999">
<tr><td><b>No.</td><td><b>Kode</b></td><td><b>Nama Mata Kuliah</b></td>
<td><b>SKS</b></td></tr>
<?php
$krs = mysql_query("SELECT * FROM krs1, makul WHERE NIMHS='$NIMHS' AND krs1.kodekuliah = makul.KDMKM ");
$jum = 0;
$i = 1;
while($k = mysql_fetch_array($krs)){
echo "<tr><td>$i</td>";
echo "<td>".$k['KDMKM']."</td>";
echo "<td>".$k['NAKMK']."</td>";
echo "<td>".$k['SKSMK']."</td></tr>";
$jum = $jum + $k['SKSMK'];
$i++;
}
echo "<tr><td colspan=3>Jumlah KRS yang diambil</td><td>$jum</td></tr>";
die("<tr><td colspan=3><font color=red>Silahkan tunggu pengeditan KRS</font></td><td></td></tr>");
?>
</table>
saya juga mau tutorial mas {klo ada}, tentang validasi yang if if'an...krna saya kurang paham jika banyak if