Advertisement
cdsatrian

daftar_nilai_ujian_xls.php

Apr 22nd, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.39 KB | None | 0 0
  1. <?php
  2. header("Content-type: application/vnd.ms-excel");
  3. header("Content-Disposition: attachment; filename=hasil_ujian_".date("d-m-Y").".xls");
  4. include_once "include/koneksi.php";
  5. $id_mp = $_REQUEST['id_mp'];
  6. $nama_mp = mysql_result(mysql_query("SELECT nama_mp FROM mapel WHERE id_mp='".$id_mp."'"),0);
  7. $sql_head = "SELECT id_ujian,nama_ujian FROM ujian where id_mp='".$id_mp."'";
  8. $sql_head_exe = mysql_query($sql_head);
  9. $head_id_ujian = array();
  10. $nama_ujian=array();
  11. $sql_nilai='';
  12. while($head = mysql_fetch_assoc($sql_head_exe)){
  13.   array_push($head_id_ujian,$head['id_ujian']);
  14.   $sql_nilai.="SUM(IF(d.id_ujian=".$head['id_ujian'].",d.nilai,0)) AS nilai_".$head['id_ujian'].",";
  15.   array_push($nama_ujian,$head['nama_ujian']);
  16. }
  17. ?>
  18. <div style="width:80%;margin:0 auto" class="daftar_pelajaran">
  19. <fieldset>
  20. <legend><center> YAYASAN PENDIDIKAN CENDRAWASIH PALU </center></legend>
  21. <legend><center> AKADEMI KEBIDANAN PALU </center></legend>
  22. <legend><center> SULAWESI TENGAH </center></legend>
  23. <legend><center>Daftar Nilai Ujian Mata Pelajaran <?php echo ucwords($nama_mp) ?> </center></legend>
  24. <table class='listing' cellpadding='0' cellspacing='0'>
  25. <tr>
  26. <th>No</th><th>NIS</th><th>Nama</th><th><?php echo implode("</th><th>",$nama_ujian)?></th><th>Rerata</th>
  27. </tr>
  28. <?php
  29. if(count($head_id_ujian) > 0){
  30.   $sql="SELECT
  31.          a.nis,
  32.          a.nama,"
  33.           .$sql_nilai
  34.          ."SUM(IF(ISNULL(d.nilai),0,d.nilai))/".count($head_id_ujian)." as rerata
  35.        FROM siswa a
  36.          LEFT JOIN (
  37.            SELECT b.*
  38.            FROM nilai b
  39.            LEFT JOIN ujian c ON b.id_ujian=c.id_ujian
  40.            WHERE c.id_mp='".$id_mp."'
  41.          ) d  ON a.nis=d.id_user
  42.        GROUP BY a.nis
  43.        ORDER BY rerata DESC";
  44.   $result = mysql_query($sql);
  45.   $no=1;
  46.   while($data = mysql_fetch_assoc($result)){
  47.     echo "<tr>";
  48.     echo "<td>".$no++."</td>";
  49.     echo "<td class='nis'>".$data['nis']."</td>";
  50.     echo "<td>".$data['nama']."</td>";
  51.     for($i = 0;$i < count($head_id_ujian); $i++){        
  52.       echo "<td class='nilai' title='".$head_id_ujian[$i]."'>"
  53.            .(empty($data['nilai_'.$head_id_ujian[$i]])?"--":number_format($data['nilai_'.$head_id_ujian[$i]],1))
  54.            ."</td>";
  55.     }
  56.     echo "<td>".number_format($data['rerata'],3)."</td>";
  57.     echo "</tr>";
  58.   }
  59. }
  60. else {
  61.   echo "<tr><td colspan='5'>Belum ada ujian yang dibuat</td></tr>";
  62. }
  63. ?>
  64. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement