从选项值中获取值,并在单击使用javascript后使用它从pdo函数执行查询
我想在有人点击选择选项html后显示MySQL的值 但我可以用alert来试试 我看过,但没什么用的 js: 这是我的选项选择:从选项值中获取值,并在单击使用javascript后使用它从pdo函数执行查询,javascript,php,jquery,mysql,pdo,Javascript,Php,Jquery,Mysql,Pdo,我想在有人点击选择选项html后显示MySQL的值 但我可以用alert来试试 我看过,但没什么用的 js: 这是我的选项选择: <select name="tanggal_input" id="test-dropdown" onchange="choice1(this)"> <?php while ($row = $tgal->fetch(PDO::FETCH_ASSOC)) { echo '<option value="'.$r
<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>
问题:我需要从option select中获取函数PDO的值,并在有人单击option select时在同一页面中执行查询
我该怎么做?有什么例子吗
编辑:我不使用另一个文件来显示结果,就像有人标记duplicate post一样,因为所有结果都是在一个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
}
?>
查看一下@LouysPatriceBesette的可能副本,这样就不可能执行我想要的操作了?因为客户机和服务器是另一个世界--@MattS非常感谢,我先读一下,看一看可能重复的@louyspatricebesette,所以不可能做我想做的事情?因为客户端和服务器是另一个世界--@MattS非常感谢,我先读一下,
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;
}
<?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
}
?>