Advertisement
cdsatrian

rerata

Apr 21st, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.11 KB | None | 0 0
  1. <?php
  2. // current time
  3. $mtime = microtime();
  4. // split seconds and microseconds
  5. $mtime = explode(" ",$mtime);
  6. // create a single value for statr time
  7. $mtime = $mtime[1] + $mtime[0];
  8. $tstart = $mtime;
  9. include_once "include/koneksi.php";
  10. $id_mp = $_REQUEST['id_mp'];
  11. $nama_mp = mysql_result(mysql_query("SELECT nama_mp FROM mapel WHERE id_mp='".$id_mp."'"),0);
  12. //ambil data ujian pada id_mp ini sebagai header
  13. $sql_head = "SELECT id_ujian,nama_ujian FROM ujian where id_mp='".$id_mp."'";
  14. $sql_head_exe = mysql_query($sql_head);
  15. $head_id_ujian = array();
  16. $nama_ujian=array();
  17. $sql_nilai='';
  18. while($head = mysql_fetch_assoc($sql_head_exe)){
  19.   array_push($head_id_ujian,$head['id_ujian']);
  20.   $sql_nilai.="SUM(IF(d.id_ujian=".$head['id_ujian'].",d.nilai,0)) AS nilai_".$head['id_ujian'].",";
  21.   array_push($nama_ujian,$head['nama_ujian']);
  22. }
  23. ?>
  24. <div style="width:80%;margin:0 auto" class="daftar_pelajaran">
  25. <fieldset>
  26. <legend>Daftar Nilai Ujian Mata Pelajaran <?php echo ucwords($nama_mp) ?></legend>
  27. <div style="margin-bottom:10px"><span onclick="download_ini()" class="tombol">Download as xls</span></div>
  28. <table class='listing' cellpadding='0' cellspacing='0' align='center'>
  29. <thead>
  30. <tr>
  31. <th>No</th><th>NIS</th><th>Nama</th><th><?php echo implode("</th><th>",$nama_ujian);?></th><th>Rerata</th><th>Aksi</th>
  32. </tr>
  33. </thead>
  34. <tbody>
  35. <?php
  36. if(count($head_id_ujian) > 0){
  37.   $sql="SELECT
  38.          a.nis,
  39.          a.nama,"
  40.           .$sql_nilai
  41.          ."SUM(IF(ISNULL(d.nilai),0,d.nilai))/".count($head_id_ujian)." as rerata
  42.        FROM siswa a
  43.          LEFT JOIN (
  44.            SELECT b.*
  45.            FROM nilai b
  46.            LEFT JOIN ujian c ON b.id_ujian=c.id_ujian
  47.            WHERE c.id_mp='".$id_mp."'
  48.          ) d  ON a.nis=d.id_user
  49.        GROUP BY a.nis
  50.        ORDER BY rerata DESC";
  51.   $result = mysql_query($sql);
  52.   $no=1;
  53.   while($data = mysql_fetch_assoc($result)){
  54.     echo "<tr>";
  55.     echo "<td>".$no++."</td>";
  56.     echo "<td class='nis'>".$data['nis']."</td>";
  57.     echo "<td>".$data['nama']."</td>";
  58.     for($i = 0;$i < count($head_id_ujian); $i++){        
  59.       echo "<td class='nilai' title='".$head_id_ujian[$i]."'>"
  60.            .(empty($data['nilai_'.$head_id_ujian[$i]])?"--":number_format($data['nilai_'.$head_id_ujian[$i]],1))
  61.            ."</td>";
  62.     }
  63.     echo "<td>".number_format($data['rerata'],3)."</td>";
  64.     echo "<td><span class='tombol_mini edit' onclick='edit_nilai(this)'>Nilai</span></td>";
  65.     echo "</tr>";
  66.   }
  67. }
  68. else {
  69.   echo "<tr><td colspan='5'>Belum ada ujian yang dibuat</td></tr>";
  70. }
  71. ?>
  72. </tbody>
  73. </table>
  74. <div style='color:#1717BF;font-size:90%;font-weight:bolder;font-style:italic'>--- &nbsp;&nbsp;berarti belum dikerjakan</div>
  75. <?php
  76. // current time
  77. $mtime = microtime();
  78. // split seconds and microseconds
  79. $mtime = explode(" ",$mtime);
  80. // create a single value for statr time
  81. $mtime = $mtime[1] + $mtime[0];
  82. $tend = $mtime;
  83. // hitung waktu eksekusi
  84. $totaltime = ($tend - $tstart);
  85. // Output the result
  86. printf ("This page was generated in %f seconds.", $totaltime);
  87. ?>
  88. <div class="kembali" onclick="kembali_lagi()">Kembali</div>
  89. <script >      
  90. function kembali_lagi(){
  91.   $("#content").html(info_loading).load("daftar_nilai_mp.php");
  92. }
  93. function download_ini(){
  94.   var id_mp = "<?php echo $id_mp ?>";
  95.   window.open("daftar_nilai_ujian_xls.php?id_mp="+id_mp);
  96. }
  97. function edit_nilai(elm){
  98.   var tmb_reset = "<span style='margin-left:5px' class='hapus' onclick='reset_nilai(this)'></span>";
  99.   $(elm).parent().parent().find("td.nilai").each(function(){
  100.     if($(this).text() != "--"){
  101.       $(tmb_reset).appendTo(this);
  102.     }
  103.   })
  104. }
  105. function reset_nilai(elm){
  106.   var nis = $(elm).parent().parent().find("td.nis").eq(0).text();
  107.   var id_ujian = $(elm).parent().attr("title");
  108.   // hapus nilai siswa pada ujian tersebut
  109.   var url = "hapus_nilai_ujian.php";
  110.   $.post(url,{nis:nis,id_ujian:id_ujian},function(hasil){
  111.     if(hasil == 1){
  112.       $(elm).parent().css({"background":"#BBEEBB"}).text("---");
  113.     }
  114.     else {
  115.       alert("gagal dihapus .......");
  116.     }      
  117.   })
  118. }              
  119. </script>
  120. <style>
  121. .hapus:hover{
  122.   cursor:pointer;
  123. }
  124. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement