0

私はこのようなmysqlテーブルを持っています:

| IDPRAKTIKAN |       NAMAUSER | MODULKE | NILAI | STATUS_TUGASAKHIR | TAHUNAJARAN | SEMESTER |
-----------------------------------------------------------------------------------------------
|  3332081478 |   Ade Dwinanto |       0 |     3 |                 1 |       09/10 |        3 |
|  3332081478 |   Ade Dwinanto |       1 |    55 |                 1 |       09/10 |        3 |
|  3332081478 |   Ade Dwinanto |       2 |    54 |                 1 |       09/10 |        3 |
|  3332081478 |   Ade Dwinanto |       3 |    45 |                 1 |       09/10 |        3 |
|  3332081478 |   Ade Dwinanto |       4 |    62 |                 1 |       09/10 |        3 |
|  3332081478 |   Ade Dwinanto |       5 |    20 |                 1 |       09/10 |        3 |
|  3332081483 | Arya Prasettyo |       0 |     3 |                 1 |       09/10 |        3 |
|  3332081483 | Arya Prasettyo |       1 |    55 |                 1 |       09/10 |        3 |
|  3332081483 | Arya Prasettyo |       2 |    53 |                 1 |       09/10 |        3 |
|  3332081483 | Arya Prasettyo |       3 |    47 |                 1 |       09/10 |        3 |
|  3332081483 | Arya Prasettyo |       4 |    60 |                 1 |       09/10 |        3 |
|  3332081483 | Arya Prasettyo |       5 |    20 |                 1 |       09/10 |        3 |

これはMySQLの私のデータです(sqlfiddle.com)

そしてこれは私のPHPコードです:

<?php
   $setting_tahunajaranget = $_GET['setting_tahunajaran'];
   $setting_kodepraktikumget = $_GET['setting_kodepraktikum'];
   $nama_praktikum = $_GET['nama_praktikum'];
   $setting_semesterget = $_GET['setting_semester'];

$query2 = "SELECT `nilai` AS semester FROM `nilaipraktikum` WHERE `modulke`= 0 LIMIT 0, 30 ";
$data   = mysql_fetch_row(mysql_query($query2));
        $query = "SELECT `idpraktikan`,namauser,`modulke`, `nilai`,`status_tugasakhir`,`tahunajaran`,`semester` FROM `nilaipraktikum` LEFT JOIN tabeluser ON tabeluser.npmuser = nilaipraktikum.idpraktikan WHERE `tahunajaran` = '$setting_tahunajaranget' AND`kodepraktikum` = '$setting_kodepraktikumget' AND `semester` = '$setting_semesterget' ";


        $result = mysql_query($query);
    if ($data = mysql_fetch_row($result)>=1)
    {

   $nilai   =   $data['nilai'];
        if ($nilai = $setting_semesterget);

echo "<table width='auto' border='1' cellpadding='3' cellspacing='3' align='center'>
  <tr>
    <td align='center' valign='middle'><strong>No</strong></td>
    <td align='center' valign='middle'><strong>Nama</strong></td>
    <td align='center' valign='middle'><strong>NPM</strong></td>";

        for($i=1;$i<=$jml_modul;$i++) {
            echo "<td align='center' valign='middle'><strong>Modul Ke-".$i."</strong></td>"; 
        }

echo    "<td align='center' valign='middle'><strong>Rata-Rata</strong></td>";

    if ($setting_status_ta=0)
    {
    }
    if ($setting_status_ta=1)
    {
    echo"<td align='center' valign='middle'><strong>Nilai Tugas Akhir</strong></td>";
    }

echo    "<td align='center' valign='middle'><strong>Nilai Akhir</strong></td>
    <td align='center' valign='middle'><strong>Grade</strong></td>
  </tr>";

        while(list($nim,$nama,$modulke,$nilai,$nilai_tugasakhir) = mysql_fetch_row($result)) {
            $array_nim[$nim] = $nim;
            $array_nama[$nim] = $nama;
            $array_nilai[$nim][$modulke]= $nilai;
            $array_nilaita[$nim][$nilai_tugasakhir]= $nilai_tugasakhir;

        }

            foreach($array_nim as $nim) {
            echo "<tr><td align='center' valign='middle'>".(++$nomor)."</td>";
            echo "<td align='center' valign='middle'>".$nim."</td>";
            echo "<td align='center' valign='middle'>".$array_nama[$nim]."</td>";

            for($i=1;$i<=$jml_modul;$i++) 
            {
                echo "<td align='center' valign='middle'>".$array_nilai[$nim][$i]."</td>"; 
                $nilaimodul += (array_sum(array($array_nilai[$nim][$i])));

            }
                            $ratarata = ($nilaimodul);

            echo "<td align='center' valign='middle'>".round ($ratarata,2)."</td>";
$ntugasakhir = $array_nilai[$nim][$jml_modul-($jml_modul-1)];


    if ($setting_status_ta=0)
    {
    }
    if ($setting_status_ta=1)
    {
            echo "<td align='center' valign='middle'>".round ($ntugasakhir,2)."</td>";
    }


$nialiakhirpraktikum = $ntugasakhir+$ratarata;
            echo "<td align='center' valign='middle'>".round ($nialiakhirpraktikum,1)."</td>";
    if ($nialiakhirpraktikum>79)
                                    $grade="A";
                                 else if ($nialiakhirpraktikum<=79 AND $nialiakhirpraktikum>67)
                                    $grade="B";
                                 else if ($nialiakhirpraktikum<=67 AND $nialiakhirpraktikum>55)
                                    $grade="C";
                                 else if ($nialiakhirpraktikum<=55 AND $nialiakhirpraktikum>44)
                                    $grade="D";
                                 else
                                    $grade="E"; 
            echo "<td align='center' valign='middle'>".$grade."</td>";
            echo "</tr>";
        }
echo "</table>";
            echo "<br/> <a href='javascript:history.back()'>Klik Disini Untuk Kembali</a>";

    }    
?>

私の質問ですが、なぜRata-Rata(平均的なNILAI)の列で、配列の結果を前の配列の結果と合計したのですか?詳しくはこちらの写真をご覧ください。(リンク画像:https ://www.diigo.com/item/image/3gviv/3m98?size = o )

一方、結果はこの写真のような列を平均したいと思います。(リンク画像:https ://www.diigo.com/item/image/3gviv/6ke4?size = o )

私のスクリプトの何が問題になっていますか?

注意:列Nilai Tugas AkhirNilaiAkhirグレードはまだ修正されていません。

4

1 に答える 1

0

初期化変数を追加するだけです

$nilaimodul = 0; // try adding this to your code
for($i=1;$i<=$jml_modul;$i++) 
{
    echo "<td align='center' valign='middle'>".$array_nilai[$nim][$i]."</td>"; 
    $nilaimodul += (array_sum(array($array_nilai[$nim][$i])));
}
$ratarata = ($nilaimodul);
于 2012-12-17T11:45:07.157 に答える