dpw30157 2017-08-05 14:11
浏览 53

从选项值中获取值并使用它来点击使用javascript后从pdo函数执行查询

I want to display value from MySQL after someone click select option html,

but I just can use alert to try.

I've seen this post but nothing I can use,

js:

function choice1(select) {
    alert(select.options[select.selectedIndex].text);
}

this is my option select:

<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>

and this is the function (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;
    }

Issue : I need to get value from option select to my function PDO and execute query in the same page when someone clicking option select.

how can I do that? there's some example?

EDIT: I don't use another file to display the result like what someone tag duplicate post, because all the result is on 1 php file like this

<?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
        }
        ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据