我想将结果正常化的结果保存到同一数据库中的另一个表中。例如,在使用php进行计数之前,我使用table1
作为原始数据,并将其用于计算Normalitation Matriks
。我想将结果保存到新table2
。
代码:
<?php
//use connection
include("koneksi.php");
//width
$bobot = array(0.50, 0.35, 0.15);
//show Name
function getNama($id){
$q =mysql_query("SELECT * FROM tbcalon where idCalon = '$id'");
$d = mysql_fetch_array($q);
return $d['nama'];
}
//Select table tbmatrik
$sql = mysql_query("SELECT * FROM tbmatrik");
//Buat tabel untuk menampilkan hasil
echo "<H3>Matrik Awal</H3>
<table width=500 style='border:1px; #ddd; solid; border-collapse:collapse' border=1>
<tr>
<td>No</td><td>Nama</td><td>Jarak</td><td>Harga</td><td>Fasilitas</td>
</tr>
";
$no = 1;
while ($dt = mysql_fetch_array($sql)) {
echo "<tr>
<td>$no</td><td>".getNama($dt['idCalon'])."</td><td>$dt[Kriteria1]</td><td>$dt[Kriteria2]</td><td>$dt[Kriteria3]</td>
</tr>";
$no++;
}
echo "</table>";
//Normalitation
$crMax = mysql_query("SELECT max(Kriteria1) as maxK1,
max(Kriteria2) as maxK2,
max(Kriteria3) as maxK3
FROM tbmatrik");
$max = mysql_fetch_array($crMax) or die("Query failed with error: ".mysql_error());
//Count Normalitation
$sql2 = mysql_query("SELECT * FROM tbmatrik");
//Buat tabel untuk menampilkan hasil
echo "<H3>Matrik Normalisasi</H3>
<table width=500 style='border:1px; #ddd; solid; border-collapse:collapse' border=1>
<tr>
<td>No</td><td>Nama</td><td>Jarak</td><td>Harga</td><td>Fasilitas</td>
</tr>
";
$no = 1;
while ($dt2 = mysql_fetch_array($sql2)) {
echo "<tr>
<td>$no</td><td>".getNama($dt2['idCalon'])."</td><td>".round($dt2['Kriteria1']/$max['maxK1'],2)."</td><td>".round($dt2['Kriteria2']/$max['maxK2'],2)."</td><td>".round($dt2['Kriteria3']/$max['maxK3'],2)."</td>
</tr>";
$no++;
}
echo "</table>";
//
答案 0 :(得分:0)
只是使用这样的东西?
$query = "INSERT INTO table2(/*insert table field names here*/) VALUES (value1, value2, value3 etc...)";
$result = mysqli_query($connectionName, $query);