Read 142 times | Created 2013-02-20 02:39:54 | Updated 2013-02-20 02:41:39 | | |

 

<?php
/*********************************  
FILENAME  : nama.kelas.php  
CREATE BY  : cahya dsn  
CREATE DATE : 2013-02-20  
**********************************  
**** CONTOH DATABASE ********
#table creation  

USE `test`;  
DROP TABLE IF EXISTS `tbl_kelas`;
CREATE TABLE IF NOT EXISTS `tbl_kelas` (
  `kode_kelas` tinyint(2) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key untuk tbl_kelas',
  `nama_kelas` varchar(30) NOT NULL COMMENT 'nama kelas',
  PRIMARY KEY(`kode_kelas`)
) ENGINE=MyISAM COMMENT 'table untuk menyimpan data kelas';

INSERT INTO `tbl_kelas`(`kode_kelas`,`nama_kelas`)
VALUES 
(NULL,'kelas1'),
(NULL,'kelas2'),
(NULL,'kelas3'),
(NULL,'kelas4'),
(NULL,'kelas5'),
(NULL,'kelas6');

DROP TABLE IF EXISTS `tbl_pelajaran`;
CREATE TABLE IF NOT EXISTS `tbl_pelajaran` (
  `kode_pelajaran` tinyint(2) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key untuk tbl_pelajaran',
  `nama_pelajaran` varchar(30) NOT NULL COMMENT 'nama pelajaran',
  PRIMARY KEY(`kode_pelajaran`)
) ENGINE=MyISAM COMMENT 'table untuk menyimpan data pelajaran';

INSERT INTO `tbl_pelajaran`(`kode_pelajaran`,`nama_pelajaran`)
VALUES 
(NULL,'matematika'),
(NULL,'bahasa indonesia'),
(NULL,'PKN'),
(NULL,'SBK'),
(NULL,'ilmu pengetahuan alam'),
(NULL,'ilmu pengetahuan sosial'),
(NULL,'olahraga'),
(NULL,'agama');

DROP TABLE IF EXISTS `tbl_nilai`;
CREATE TABLE IF NOT EXISTS `tbl_nilai` (
  `id_nilai` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key untuk tbl_nilai',
  `no_induk` varchar(10) NOT NULL COMMENT 'no induk siswa',
  `nama` varchar(30) NOT NULL COMMENT 'nama siswa',
  `kode_pelajaran` tinyint(2) unsigned NOT NULL,
  `kode_kelas` tinyint(2) unsigned NOT NULL,
  `nilai` float NOT NULL DEFAULT 0.0,
  PRIMARY KEY(`id_nilai`)
) ENGINE=MyISAM COMMENT 'table untuk menyimpan data nilai';

INSERT INTO `tbl_nilai`(`no_induk`,`nama`,`kode_pelajaran`,`kode_kelas`,`nilai`)
VALUES 
('1234567890','agus',1,1,70.5),
('1234567890','agus',2,1,82.3),
('1234567890','agus',3,1,90.1),
('1234567890','agus',4,1,62.4),
('1234567890','agus',5,1,77.5),
('1234567890','agus',6,1,60.9),
('1234567890','agus',7,1,72.9),
('1234567890','agus',8,1,97.5),
('1234567891','budi',1,2,90.0),
('1234567891','budi',2,2,82.7),
('1234567891','budi',3,2,90.1),
('1234567892','citra',4,4,54.4),
('1234567892','citra',5,4,87.3),
('1234567892','citra',6,4,66.4),
('1234567893','dewa',7,5,72.7),
('1234567893','dewa',8,5,87.5);
**** AKHIR CONTOH DATABASE ********
*/
//database configuration  
$dbhost='localhost';  
$dbuser='root';  
$dbpass='';  
$dbname='test';  
//database connection  
$conn=mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname,$conn);
?>
<!DOCTYPE html>
<html>
  <head>
    <title>Nilai Siswa</title>
  </head>
  <body>
    <div>Nilai Siswa</div>
    <form name="cari" action="" method="post">
    <div align="left">
      <table>
      <tr>
        <td>Masukan- Kelas</td>
        <td>:</td>
        <td>
          <select name="kode_kelas">
            <option value="0">-- Pilih Kelas --</option>
            <?php
            $kelas=mysql_query("SELECT kode_kelas,nama_kelas FROM tbl_kelas ORDER BY nama_kelas");
            while($row1=mysql_fetch_array($kelas)){
              echo '<option value="'.$row1['kode_kelas'].'">'.$row1['nama_kelas'].'</option>';
            }
            ?> 
          </select>
        </td>
      </tr>
      <tr>
        <td>Masukan- Kode Pelajaran</td> 
        <td>:</td>
        <td>
          <select name="kode_pelajaran"> 
            <option value="0">-- Pilih Mata Pelajaran --</option>
            <?php
            $mapel=mysql_query("SELECT kode_pelajaran,nama_pelajaran FROM tbl_pelajaran ORDER BY kode_pelajaran");
            while($row2=mysql_fetch_array($mapel)){
              echo '<option value="'.$row2['kode_pelajaran'].'">'.$row2['nama_pelajaran'].'</option>';
            }
            ?> 
          </select>
        </td>
      </tr>
      <tr>
        <td colspan="3">
          <input type="submit" name="submit" value=" Cari " />
        </td>
      </tr>
      </table>
    </div>
    </form>
    <?
    if(isset($_POST['kode_kelas']) && $_POST['kode_pelajaran']){
      $sql = "SELECT no_induk,nama,nilai "
            ."FROM tbl_nilai "
            ."WHERE kode_kelas LIKE '%".$_POST['kode_kelas']."%' OR kode_pelajaran LIKE '%".$_POST['kode_pelajaran']."%' "
            ."ORDER BY no_induk";
      $hasil = mysql_query($sql);
      if(mysql_num_rows($hasil) > 0){
        echo "<table border='1'>"
            ."<tr>"
            ."<th>No</th>"
            ."<th>No. Induk</th>"
            ."<th>Nama</th>"
            ."<th>Nilai</th>"
            ."</tr>n";
        $no = 1;
        while ($arData=mysql_fetch_array($hasil))
        {
          echo "<tr>"
              ."<td>$no</td>"
              ."<td>".$arData['no_induk']."</td>"
              ."<td>".$arData['nama']."</td>"
              ."<td>".$arData['nilai']."</td>"
              ."</tr>n";
          $no++;
        }
        echo "</table>n";
      }
      else
      {
        echo 'Data Tidak ditemukan';
      }
    }
    ?> 
  </body>
</html>