Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- USE test;
- DROP TABLE IF EXISTS `pegawai`;
- CREATE TABLE IF NOT EXISTS `pegawai` (
- `nik_pegawai` CHAR(10) NOT NULL,
- `nama` varchar(25) NOT NULL,
- PRIMARY KEY(`nik_pegawai`)
- ) ENGINE=MyISAM COMMENT='tabel untuk menyimpan data pegawai';
- INSERT INTO `pegawai`(`nik_pegawai`,`nama`)
- VALUES
- ('2007090301','Agus Pambagyo'),
- ('2007091002','Budi Setiawan'),
- ('2007091703','Cindy Fitriani'),
- ('2007092304','Desi Anggraeni'),
- ('2007092805','Eman Sutarman'),
- ('2007100706','Firmansyah'),
- ('2007101207','Gina Fauzia');
- DROP TABLE IF EXISTS `nilai_kriteria`;
- CREATE TABLE IF NOT EXISTS `nilai_kriteria` (
- `nik_pegawai` CHAR(10) NOT NULL,
- `nilai` FLOAT NOT NULL DEFAULT 0,
- `kode_kriteria` CHAR(3) NOT NULL
- ) ENGINE=MyISAM COMMENT='tabel untuk menyimpan data nilai kriteria';
- INSERT INTO `nilai_kriteria`(`nik_pegawai`,`nilai`,`kode_kriteria`)
- VALUES
- ('2007090301',8.23,'K01'),
- ('2007090301',8.67,'K02'),
- ('2007090301',9.43,'K03'),
- ('2007090301',5.43,'K04'),
- ('2007090301',6.25,'K05'),
- ('2007090301',8.21,'K06'),
- ('2007091002',8.47,'K01'),
- ('2007091002',8.55,'K02'),
- ('2007091002',7.83,'K03'),
- ('2007091002',6.28,'K04'),
- ('2007091002',7.93,'K05'),
- ('2007091002',7.43,'K06'),
- ('2007091703',8.26,'K01'),
- ('2007091703',8.81,'K02'),
- ('2007091703',7.22,'K03'),
- ('2007091703',5.93,'K04'),
- ('2007091703',8.75,'K05'),
- ('2007091703',7.25,'K06'),
- ('2007092304',7.83,'K01'),
- ('2007092304',7.43,'K02'),
- ('2007092304',8.90,'K03'),
- ('2007092304',9.21,'K04'),
- ('2007092304',7.83,'K05'),
- ('2007092304',8.77,'K06'),
- ('2007092805',8.23,'K01'),
- ('2007092805',7.33,'K02'),
- ('2007092805',8.32,'K03'),
- ('2007092805',9.21,'K04'),
- ('2007092805',5.83,'K05'),
- ('2007092805',8.53,'K06'),
- ('2007100706',7.39,'K01'),
- ('2007100706',8.32,'K02'),
- ('2007100706',8.91,'K03'),
- ('2007100706',9.51,'K04'),
- ('2007100706',8.96,'K05'),
- ('2007100706',7.27,'K06'),
- ('2007101207',7.28,'K01'),
- ('2007101207',6.56,'K02'),
- ('2007101207',8.20,'K03'),
- ('2007101207',9.13,'K04'),
- ('2007101207',7.25,'K05'),
- ('2007101207',6.43,'K06');
- */
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Bobot</title>
- <style>
- * {font-family: verdana,arial,sans-serif;font-size:12px;color:#339;}
- td{text-align: center;}
- </style>
- </head>
- <body>
- <div id='container'>
- <?php
- $dbhost='localhost';
- $dbuser='root';
- $dbpass='';
- $dbname='test';
- $db=new mysqli($dbhost, $dbuser, $dbpass, $dbname);
- $sql="
- SELECT
- a.nik_pegawai,
- GROUP_CONCAT(a.kode_kriteria) AS kriteria,
- GROUP_CONCAT(a.nilai/c.maks) AS bobot
- FROM nilai_kriteria a
- JOIN pegawai b USING(nik_pegawai)
- JOIN (
- SELECT kode_kriteria,MAX(nilai) AS maks
- FROM nilai_kriteria
- GROUP BY kode_kriteria
- ) c USING(kode_kriteria)
- GROUP BY b.nik_pegawai
- ";
- $data=array();
- $kode=array();
- if($result=$db->query($sql))
- {
- while($record = $result->fetch_object())
- {
- $kriteria=explode(",",$record->kriteria);
- $kode=array_merge($kode,$kriteria);
- $bobot=explode(",",$record->bobot);
- $num_col=count($kriteria);
- if(isset($data[$record->nik_pegawai]))
- {
- for($i=0;$i<$num_col;$i++)
- {
- $data[$record->nik_pegawai][$kriteria[$i]]=$bobot[$i];
- }
- }
- else
- {
- $data[$record->nik_pegawai]=array();
- for($i=0;$i<$num_col;$i++)
- {
- $data[$record->nik_pegawai]['nik']=$record->nik_pegawai;
- $data[$record->nik_pegawai][$kriteria[$i]]=$bobot[$i];
- }
- }
- }
- $kode_kriteria=array_unique($kode);
- $num=count($kode_kriteria);
- echo "<table border='1'>\n"
- ."<tr><th>NIK\Kriteria</th>";
- foreach($kode_kriteria as $kd)
- {
- echo "<th>".$kd."</th>";
- }
- echo "</tr>\n";
- foreach($data as $dt)
- {
- echo "<tr>"
- ."<th>".$dt['nik']."</th>";
- for($j=0;$j<$num;$j++)
- {
- echo "<td>".(isset($dt[$kode_kriteria[$j]])?$dt[$kode_kriteria[$j]]:" ")."</td>";
- }
- echo "</tr>\n";
- }
- echo "</table>";
- }
- ?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement