btw ini ada share sedikit ttg membuat soal random.....yang beda disini adalah sy menggunakan session sebagai alat perekam soal random, ybs....
keutungannya :
+SOAL BISA RANDOM
+SOAL MUNCUL SATU DEMI SATU
+MESKIPUN PENGGUNA BERPINDAH TAB BROWSER / REFRESH BERULANG TAPI SOAL TETAP STABIL
Nah itu .............
<?php
session_start();
$_SESSION["selesai"]=0;
if(!isset($_SESSION["ckat"])){
$kat=$_GET["kat"];
$_SESSION["chasil"]=0;
$_SESSION["crekap"]="";
$_SESSION["ckat"]=$kat;
$_SESSION["cawal"]="";
$sql="select * from `tb_soal` where matapelajaran='$kat'";
$jumsoal=getJum($conn,$sql);
$_SESSION["jumsoal"]=$jumsoal;
$_SESSION['student']=array();
$i=0;
$sqlc="select * from `$tbsoal` where matapelajaran='$kat' order by rand()";
$jumc=getJum($conn,$sqlc);
$arr=getData($conn,$sqlc);
foreach($arr as $d) {
$id_soal=$d["id_soal"];
$M[$i]=$id_soal;
//echo "$i=".$id_soal."<br>";
$i++;
}
$_SESSION["student"]=$M;
}
//-----------
for($i = 0 ; $i < count($_SESSION["student"]) ; $i++) {
//echo $i.'==='.$_SESSION["student"][$i].'<br>';
}
if(!isset($_SESSION["m"])){
$_SESSION["m"]=0;
}
if(isset($_GET["Pilih"])){
$kat=$_SESSION["ckat"];
$sql="select * from `tb_soal` where matapelajaran='$kat'";
$jumsoal=getJum($conn,$sql);
$x=$_SESSION["m"];
if($x==0){
$_SESSION["cawal"]=WKT(date("Y-m-d"))." ". date("H:i:s");
}
$id_soal=$_SESSION["student"][$x];
$_SESSION["m"]++;
//jawaban=A&id_soal=27&jawab_benar=B&Pilih=Pilih&mnu=soal
$jawaban=$_GET["jawaban"];
$id_soal=$_GET["id_soal"];
$jawab_benar=$_GET["jawab_benar"];
$hasil="Salah";
if($jawab_benar==$jawaban){
$hasil="Benar";$_SESSION["chasil"]=$_SESSION["chasil"]+1;
$_SESSION["crekap"].="Soal ".$_SESSION["m"]." (ID:$id_soal):Benar,";
}
else{
$_SESSION["crekap"].="Soal ".$_SESSION["m"]." (ID:$id_soal):Salah,";
}
if($_SESSION["m"]>=($jumsoal)){
//if($_SESSION["m"]>=99){//artinya dari 1000soal hanya 100 yg ditampilkan
$ahir=WKT(date("Y-m-d"))." ". date("H:i:s");
$waktu="Jumlah Soal: ".$_SESSION["jumsoal"].", Waktu Pengerjaan: ".$_SESSION["cawal"]." s/d ".$ahir." WIB";
$sql="INSERT INTO `tb_hasil` (`id`, `kode_user`, `id_soal`, `rekapitulasi`, `hasil`, `keterangan`)
VALUES ('', '".$_SESSION["cid"]."', '".$_SESSION["ckat"]."', '".$_SESSION["crekap"]."', '".$_SESSION["chasil"]."', '$waktu')";
$simpan=process($conn,$sql);
$_SESSION["selesai"]=1;
}
}
if($_SESSION["selesai"]==1){
unset($_SESSION["selesai"]);
unset($_SESSION["m"]);
unset($_SESSION["student"]);
unset($_SESSION["crekap"]);
unset($_SESSION["chasil"]);
unset($_SESSION["jumsoal"]);
$_SESSION["student"]=array();
unset($_SESSION["student"]);
unset($_SESSION["m"]);
unset($_SESSION["ckat"]);
session_destroy();
echo "<script>alert('terimakasih atas partisipasinya.......See You Later...');
document.location.href='index.php';</script>";
}
else{
$m=$_SESSION["m"];
$id_soal=$_SESSION["student"][$m];
//echo"M=$m==$id_soal<br>";
$no=$m+1;
$sql="select * from `tb_soal` where id_soal='$id_soal'";
$d=getField($conn,$sql);
$id_soal=$d["id_soal"];
$mata_pelajaran=$d["mata_pelajaran"];
$soal=$d["soal"];
$jawab_a=$d["jawab_a"];
$jawab_b=$d["jawab_b"];
$jawab_c=$d["jawab_c"];
$jawab_d=$d["jawab_d"];
$jawab_benar=$d["jawab_benar"];
$gambar=$d["gambar"];
$kat=$_SESSION["ckat"];
?>
<form name='form1' method='get' action=''>
<table width='100%' border='0'>
<tr>
<td colspan='4'> </td>
</tr>
<tr>
<td width='23%' rowspan='3' align='center' valign='middle'>
<a href='#' onclick='buka(\"soal/zoom.php?id=$id_soal\")'><img src='graduation.jpg' width='150' height='180' /></a>
</td>
<td colspan='3'><h1><?php echo $no.". ".$soal;?> </h1><hr></td>
</tr>
<tr>
<td colspan="3"><font size="+2">
<input type="radio" id="pil" name="jawaban" value="A">A. <?php echo $jawab_a;?><br>
<input type="radio" id="pil" name="jawaban" value="B">B. <?php echo $jawab_b;?><br>
<input type="radio" id="pil" name="jawaban" value="C">C. <?php echo $jawab_c;?><br>
<input type="radio" id="pil" name="jawaban" value="D">D. <?php echo $jawab_d;?><br>
<input type="hidden" id="id_soal" name="id_soal" value="<?php echo $id_soal;?>"><br />
<input type="hidden" id="jawab_benar" name="jawab_benar" value="<?php echo $jawab_benar;?>">
</font><br /><br /><br />
<input type="submit" value="Pilih" name="Pilih">
<input type="hidden" value="soal" name="mnu">
<input type="hidden" value="<?php echo $kat;?>" name="kat">
</td>
</tr>
<tr>
<td width="20%"> </td>
<td width="28%"> </td>
<td width="29%" colspan='2'> </td>
</tr>
</table>
</form>
<?php
}
?>
login pengguna...
'
tampilan memilih kategori soal yang dibuka/aktif
menikmati soal2 yang aneh....
Walau di refresh...id soal tetap konstan...
Tidak ada komentar:
Posting Komentar