1

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
        }
        ?>
Flix
  • 444
  • 8
  • 20
  • Have a look [here](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Louys Patrice Bessette Aug 05 '17 at 14:18
  • 1
    Possible duplicate of [Post result from a query via php in same page with Ajax](https://stackoverflow.com/questions/10421480/post-result-from-a-query-via-php-in-same-page-with-ajax) – Matt S Aug 05 '17 at 14:19
  • @LouysPatriceBessette so it's not possible to do what i want? because client and server is "another world" -_- – Flix Aug 05 '17 at 14:26
  • @MattS thanks a lot, ill read it first, – Flix Aug 05 '17 at 14:27

0 Answers0