Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery KeyUp Live Search. How to?
    primarykey
    data
    text
    <p>I am trying to find out why is it that I can get my live search to work but it returns all results from mysql table no matter what I type. Perhaps you could help?</p> <p>I am trying to get the previous request and initiate a new one on each keyup.</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;Help Tool 2.0&lt;/title&gt; &lt;link type="text/css" rel="stylesheet" href="assets/css/index.css" /&gt; &lt;script type="text/javascript" src="js/jquery-1.7.1.min.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;script type="text/javascript"&gt; $(function(){ $('#search-box').keyup(function() { $("#results").html(''); var xhr; var keywords = $(this).val(); if(xhr != null) xhr.abort(); xhr = $.get("search.php", {q: keywords}, function() { //alert("success"); }) .success(function(data) { xhr = null; //alert("second success"); $("#results").html(data); }) }); }); &lt;/script&gt; &lt;input id="search-box" name="q" type="text" /&gt; &lt;div id="results"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>And the PHP:</p> <pre><code>&lt;?php include_once ('database_connection.php'); if(isset($_GET['q'])){ $keyword = trim($_GET['q']) ; $keyword = mysqli_real_escape_string($dbc, $keyword); $query = "select topictitle,topicdescription from topics where topictitle like '%$q%' or topicdescription like '%$q%'"; //echo $query; $result = mysqli_query($dbc,$query); if($result){ if(mysqli_affected_rows($dbc)!=0){ while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){ echo '&lt;p&gt; &lt;b&gt;'.$row['topictitle'].'&lt;/b&gt; '.$row['topicdescription'].'&lt;/p&gt;'; } }else { echo 'No Results for :"'.$_GET['q'].'"'; } } }else { echo 'Parameter Missing'; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload