Page 1 of 1

i have created drop down and i want to filter my html tab

Posted: Tue Sep 29, 2015 3:04 am
by mehdy.mahmood
i have created drop down and i want to filter my html table by selecting the dropdown , but when i select the drop down it create 2 html table ,, but i need one html table

Code: Select all

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>

[inline]  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
  <div id="txtHint"></div>
  <script>
        function showUser(str) {
            //  alert (str);

            if (str == "") {
                document.getElementById("txtHint").innerHTML = "";
                return;
            } else {
                if (window.XMLHttpRequest) {
                  
                    // code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp = new XMLHttpRequest();
                } else {
                    // code for IE6, IE5
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange = function () {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                        document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
                    }
                }
                xmlhttp.open("GET", "new.php?q=" + str, true);
                xmlhttp.send();
            }
        }
    </script>[/inline]


<body>
    <form>


        <select onchange="showUser(this.value)">

            <option value="1" >
                1
            </option>

            <option value="3" >
                3
            </option>


        </select> 


        <?php
        $con = mysqli_connect("localhost", "root", "");
        mysqli_select_db($con, "crud_tutorial");

        if (isset($_REQUEST['q'])) {
            $q = intval($_GET['q']);


//echo "$q";


            $sql = "SELECT * FROM customers WHERE id = '" . $q . "'";
            $result = mysqli_query($con, $sql);
        } else {


            $sql = "SELECT * FROM customers ";
            $result = mysqli_query($con, $sql);
        }
        echo "<table>
<tr>
<th>id</th>
<th>name</th>

</tr>";
        while ($row = mysqli_fetch_array($result)) {
            echo "<tr>";
            echo "<td>" . $row['id'] . "</td>";
            echo "<td>" . $row['name'] . "</td>";


            echo "</tr>";
        }
        echo "</table>";
        mysqli_close($con);
        ?>
    </form>
</body>

</html>