我希望在有人点击MySQL
html,
select option
的值
但我可以使用提醒尝试。
我已经看过这个post,但我无法使用,
JS:
function choice1(select) {
alert(select.options[select.selectedIndex].text);
}
这是我的选择:
<select name="tanggal_input" id="test-dropdown" onchange="choice1(this)">
<?php
while ($row = $tgal->fetch(PDO::FETCH_ASSOC))
{
echo '<option value="'.$row["tgl_input"].'">'.$row["tgl_input"].'</option>';
}
?>
</select>
<table width="100%" class="table table-striped table-bordered" id="tabeldata">
<thead>
<tr>
<th width="30px">No</th>
<th>Alternatif</th>
<th>Kriteria</th>
<th>Nilai</th>
<th width="100px">Aksi</th>
</tr>
</thead>
<tfoot>
<tr>
<th>No</th>
<th>Alternatif</th>
<th>Kriteria</th>
<th>Nilai</th>
<th>Aksi</th>
</tr>
</tfoot>
<tbody>
<?php
$no=1;
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
?>
<tr>
<td><?php echo $no++ ?></td>
<td><?php echo $row['nama_alternatif'] ?></td>
<td><?php echo $row['nama_kriteria'] ?></td>
<td><?php echo $row['nilai_rangking'] ?></td>
<td class="text-center">
<a href="rangking-ubah.php?ia=<?php echo $row['id_alternatif'] ?>&ik=<?php echo $row['id_kriteria'] ?>" class="btn btn-warning"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a>
<a href="rangking-hapus.php?ia=<?php echo $row['id_alternatif'] ?>&ik=<?php echo $row['id_kriteria'] ?>" onclick="return confirm('Yakin ingin menghapus data')" class="btn btn-danger"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
这是函数(rangking.inc.php):
function readHasil($a){
$query = "SELECT sum(bobot_normalisasi) as bbn FROM " . $this->table_name . " WHERE
id_alternatif='$a' and tgl_input = '2017-05-23' LIMIT 0,1";
// i need to get tgl_input = "..." from option select value
$stmt = $this->conn->prepare( $query );
$stmt->execute();
return $stmt;
}
function readHasil($a){
$query = "SELECT sum(bobot_normalisasi) as bbn FROM " . $this->table_name . " WHERE id_alternatif='$a' and tgl_input = '2017-05-23' LIMIT 0,1";
$stmt = $this->conn->prepare( $query );
$stmt->execute();
return $stmt;
}
问题:我需要从选项选择中获取值到我的函数PDO,并在有人点击选项选择时在同一页面中执行查询。
我该怎么做?有一些例子吗?
编辑:我没有使用其他文件来显示结果,例如某人标记重复的帖子,因为所有结果都是在这样的1个php文件中<?php
include_once 'includes/rangking.inc.php';
$pro = new Rangking($db);
$stmt = $pro->readKhusus();
?>
---some html code-----
<?php
$no=1;
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
?>
<tr>
<td><?php echo $no++ ?></td>
<td><?php echo $row['nama_alternatif'] ?></td>
<td><?php echo $row['nama_kriteria'] ?></td>
<td><?php echo $row['nilai_rangking'] ?></td>
<td class="text-center">
<a href="rangking-ubah.php?ia=<?php echo $row['id_alternatif'] ?>&ik=<?php echo $row['id_kriteria'] ?>" class="btn btn-warning"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a>
<a href="rangking-hapus.php?ia=<?php echo $row['id_alternatif'] ?>&ik=<?php echo $row['id_kriteria'] ?>" onclick="return confirm('Yakin ingin menghapus data')" class="btn btn-danger"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
</td>
</tr>
<?php
}
?>