Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // mensimulasi data dari database, soalnya nggak tau tabel dan datanya sih...
- $kritA=array(
- array("id_kriteria"=>1,"kriteria"=>"Pendidikan","nilai"=>100),
- array("id_kriteria"=>2,"kriteria"=>"Kelengkapan Dokumen","nilai"=>100),
- array("id_kriteria"=>3,"kriteria"=>"Pengalaman Kerja","nilai"=>100)
- );
- $no_urutA=array(
- array("no_urut"=>1245,"nilai_1"=>2.43,"nilai_2"=>1.485,"nilai_3"=>1.07),
- array("no_urut"=>1246,"nilai_1"=>2.595,"nilai_2"=>1.8,"nilai_3"=>0.94),
- array("no_urut"=>1247,"nilai_1"=>2.185,"nilai_2"=>1.39,"nilai_3"=>1.25),
- );
- function array_to_object($array) {
- $obj = new stdClass;
- foreach($array as $k => $v) {
- $obj->{$k} =(is_array($v))?array_to_object($v): $v;
- }
- return $obj;
- }
- // ini pura-puranya hasil dari query ke database-nya...
- $krit=array_to_object($kritA);
- $no_urut=array_to_object($no_urutA);
- // preparing data to show
- $no = 0;
- $data_fix=array();
- foreach($no_urut as $row1){
- $data_fix[$no]['no_urut']=$row1->no_urut;
- $jum = 0;
- foreach($krit as $row){
- $id = $row->id_kriteria;
- $nn = $row1->{"nilai_$id"};
- $nnn = $row->nilai/100*$nn;
- $data_fix[$no][$row->kriteria] = $nnn;
- $jum+=$nnn;
- }
- $data_fix[$no]['hasil_akhir'] = $jum;
- $hasil_akhir=array();
- foreach($data_fix as $key => $row6){
- $hasil_akhir[$key]=$row6['hasil_akhir'];
- }
- $no++;
- }
- array_multisort($hasil_akhir,SORT_DESC,$data_fix);
- ?>
- <html>
- <head>
- <title>Array Multisort</title>
- </head>
- <body>
- <table border="1">
- <thead>
- <tr>
- <th>No. Urut Pelamar</th>
- <?php
- foreach($krit as $row){
- echo "<th scope='col'>$row->kriteria</th>";
- }
- ?>
- <th>Hasil Akhir</th>
- <th>Rangking</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $rangking=1;
- foreach($data_fix as $key=>$val){
- echo "<tr>";
- foreach($val as $k=>$v){
- echo "<td>".$v."</td>";
- }
- echo "<td>$rangking</td></tr>\n";
- $rangking++;
- }
- ?>
- </tbody>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement