mehdymahmood Posted September 28, 2015 Share Posted September 28, 2015 <!DOCTYPE html><!--To change this license header, choose License Headers in Project Properties.To change this template file, choose Tools | Templatesand open the template in the editor.--><html> <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><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> Quote Link to comment https://forums.phpfreaks.com/topic/298351-when-i-select-dropdown-it-creat-extra-html-table-how-to-solve-it/ Share on other sites More sharing options...
scootstah Posted September 28, 2015 Share Posted September 28, 2015 Can you elaborate a little please? Quote Link to comment https://forums.phpfreaks.com/topic/298351-when-i-select-dropdown-it-creat-extra-html-table-how-to-solve-it/#findComment-1521763 Share on other sites More sharing options...
mehdymahmood Posted September 28, 2015 Author Share Posted September 28, 2015 Can you elaborate a little please? thnkx scootstah , 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 , thanks Quote Link to comment https://forums.phpfreaks.com/topic/298351-when-i-select-dropdown-it-creat-extra-html-table-how-to-solve-it/#findComment-1521767 Share on other sites More sharing options...
scootstah Posted September 28, 2015 Share Posted September 28, 2015 So the PHP script you are calling must be returning an HTML table, and then you're adding that to <div id="txtHint"></div> with this line: document.getElementById("txtHint").innerHTML = xmlhttp.responseText;Is the code you posted the script that you're calling with AJAX? Quote Link to comment https://forums.phpfreaks.com/topic/298351-when-i-select-dropdown-it-creat-extra-html-table-how-to-solve-it/#findComment-1521774 Share on other sites More sharing options...
mehdymahmood Posted September 28, 2015 Author Share Posted September 28, 2015 So the PHP script you are calling must be returning an HTML table, and then you're adding that to <div id="txtHint"></div> with this line: document.getElementById("txtHint").innerHTML = xmlhttp.responseText;Is the code you posted the script that you're calling with AJAX? yes its ajax Quote Link to comment https://forums.phpfreaks.com/topic/298351-when-i-select-dropdown-it-creat-extra-html-table-how-to-solve-it/#findComment-1521777 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.