Hello, everyone! I'm trying to create a livesearch, but the code doesn't work:
[ls.php]
<html><head> <title>php and ajax search</title> <script type="text/javascript" src="../jquery.js"></script></head><body><script>function showHint(str) { $("#textBoxId").change(function() //triggers when you change the value in your textbox { var value = $(this).val(); //gets the value of your textbox $.post("search.php", {id:value},function(data) $("#results").append(data); }); }}</script><p><b>Start typing a name in the input field below:</b></p><form>First name: <input type="text" onkeyup="showHint(this.value)" id="txt"></form><p>Suggestions: <span id="txtHint"></span></p></body></html>
[search.php]
<? include("../dbconfig.php"); $s=($_POST['s']); $sql=mysql_query("SELECT * FROM companies WHERE name LIKE '" .$s. "%' ") or die(mysql_error()); while($row=mysql_fetch_array($sql)) { echo $row['name']."<br>"; } ?>
Livesearch
in PHP
Posted
Hello, everyone! I'm trying to create a livesearch, but the code doesn't work:
[ls.php]
[search.php]