Postingan lainnya
data yang masuk kedatabase sama semua
misi agan agan, saya lagi mengerjakan tugas website bertemakan spk. nah disaat menentukan rangking data yang masuk kedalam database sama semua. lebih jelasnya liat gini gan
<?php
include "config.php";
$link_update="perhitungan1.php";
require_once ( 'ahp.php' );
$q="select * from kriteria order by kode";
$q=mysql_query($q);
while($h=mysql_fetch_array($q)){
$kriteria[]=array($h['id_kriteria'],$h['kode'],$h['nama']);
}
$q="select * from alternatif order by kode";
$q=mysql_query($q);
while($h=mysql_fetch_array($q)){
$alternatif[]=array($h['id_alternatif'],$h['kode'],$h['nama']);
}
for($i=0;$i<count($kriteria);$i++){
$id_kriteria[]=$kriteria[$i][0];
}
$matrik_kriteria = ahp_get_matrik_kriteria($id_kriteria);
$jumlah_kolom = ahp_get_jumlah_kolom($matrik_kriteria);
$matrik_normalisasi = ahp_get_normalisasi($matrik_kriteria, $jumlah_kolom);
$eigen_kriteria = ahp_get_eigen($matrik_normalisasi);
for($i=0;$i<count($alternatif);$i++){
$id_alternatif[]=$alternatif[$i][0];
}
for($i=0;$i<count($kriteria);$i++){
$matrik_alternatif = ahp_get_matrik_alternatif($kriteria[$i][0], $id_alternatif);
$jumlah_kolom_alternatif = ahp_get_jumlah_kolom($matrik_alternatif);
$matrik_normalisasi_alternatif = ahp_get_normalisasi($matrik_alternatif, $jumlah_kolom_alternatif);
$eigen_alternatif[$i] = ahp_get_eigen($matrik_normalisasi_alternatif);
}
$nilai_to_sort = array();
for($i=0;$i<count($alternatif);$i++){
$nilai=0;
for($ii=0;$ii<count($kriteria);$ii++){
$nilai = $nilai + ( $eigen_alternatif[$ii][$i] * $eigen_kriteria[$ii]);
}
$nilai = round( $nilai , 3);
$nilai_global[$i] = $nilai;
$nilai_to_sort[] = array($nilai, $alternatif[$i][0]);
}
sort($nilai_to_sort);
for($i=0;$i<count($nilai_to_sort);$i++){
$ranking[$nilai_to_sort[$i][1]]=(count($nilai_to_sort) - $i);
}
?>
<p> </p>
<form action="<?php echo $link_update;?>" name="" method="post" enctype="multipart/form-data">
<table class="table table-striped table-hover table-bordered">
<tdead>
<tr>
<td colspan="50">EIGEN KRITERIA DAN ALTERNATIF </td>
</tr>
<tr>
<td width="40">No</td>
<td>Perusahaan</td>
<?php
for($i=0;$i<count($kriteria);$i++){
echo '<td>'.$kriteria[$i][1].'</td>';
}
?>
<td>Nilai</td>
<td>Ranking</td>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td>Vektor Eigen</td>
<?php
for($i=0;$i<count($kriteria);$i++){
echo '<td>'.$eigen_kriteria[$i].'</td>';
}
?>
<td></td>
<td></td>
</tr>
<?php
$q="select * from alternatif order by kode";
$q=mysql_query($q);
while($h=mysql_fetch_array($q)){
$alternatif2[]=array($h['id_alternatif'],$h['kode'],$h['nama']);
}
$q="select * from ranking";
$q=mysql_query($q);
while($h=mysql_fetch_array($q)){
$nama_alternatif[]=array($h['id_ranking'],$h['nama']);
}
$nama_alternatif1=$_POST['nama_alternatif1'];
$nilai1=$_POST['nilai1'];
$ranking1=$_POST['ranking1'];
if(isset($_POST['save'])){
mysql_query("truncate table ranking"); /* kosongkan tabel nilai_kriteria */
foreach($alternatif2 as $row)
{
$row="insert into ranking values('','$nama_alternatif1','$nilai1','$ranking1')";
$row=mysql_query($row);
}
$success='good job.';
}
for($i=0;$i<count($alternatif);$i++){
echo '
<tr>
<td>'.($i+1).'</td>
<td><input type="text" name="nama_alternatif1" value="'.$alternatif[$i][1].' - '.$alternatif[$i][2].'" id="nama_alternatif" /></td>
';
for($ii=0;$ii<count($kriteria);$ii++){
echo '
<td>'.$eigen_alternatif[$ii][$i].'</td>
';
}
echo '
<td><input type="text" name="nilai1" value="'.$nilai_global[$i].'" id="nilai1" /></td>
<td><input type="text" name="ranking1" value="'.$ranking[$alternatif[$i][0]].'" id="ranking1" /></td>
</tr>
';
}
?>
</tbody>
</table>
<?php
if(!empty($error)){
echo '
<div class="alert alert-error ">
'.$error.'
</div>
';
}
if(!empty($success)){
echo '
<div class="alert alert-success ">
'.$success.'
</div>
';
}
?>
<button type="submit" name="save" class="btn blue"><i class="icon-ok"></i> Simpan</button>
</form>
begini hasil databasenya
0
1 Jawaban:
$row="insert into ranking values('','$nama_alternatif1','$nilai1','$ranking1')";
dibagian ini tambah colom tablenya kak
$row="insert into ranking (kolom yg ada ditable ranking) values('','$nama_alternatif1','$nilai1','$ranking1')";
0