Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy isnt this ajax live search working
    text
    copied!<p>*<strong>*Updated code as of 3-28</strong></p> <p><em>Index.php</em></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;jQuery Search Demonstration&lt;/title&gt; &lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $(".keywords").keyup(function(){ $('#key').html($(this).val()); $('#table').html($('.table:checked').val()); // Do the ajax call // Get the textbox value: $(this).val() // Get the radio value: $('.table:checked').val() /*$.post("search.php", { keywords: $(".keywords").val() }, function(data){ $("div#content").empty() $.each(data, function(){ $("div#content").append("- &lt;a href='prof.php?pID=" + this.pID + "'&gt;" + this.last + "&lt;/a&gt;"); }); }, "json");*/ }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; Search by: &lt;input type="radio" name="table" class="table" value="Table 1" /&gt;Professor&lt;br /&gt; &lt;input type="radio" name="table" class="table" value="Table 2" /&gt;Department&lt;br /&gt; &lt;input type="radio" name="table" class="table" value="Table 3" /&gt;Course&lt;br /&gt; &lt;input type="text" name="search" class="keywords"&gt; &lt;input type="submit" name="submit" class="search"&gt; &lt;div id="content"&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><em>Search.php</em></p> <pre><code>&lt;?php $link = mysql_connect('##',"##","##"); mysql_select_db("###", $link); $keywords = mysql_real_escape_string( $_POST["keywords"] ); $query = mysql_query("SELECT pID, lname, fname FROM Professor WHERE CONCAT(lname,fname) LIKE '%". $keywords . "%'"); $arr = array(); while( $row = mysql_fetch_array ( $query ) ) { $arr[] = array( "pID" =&gt; $row["pID"], "last" =&gt; $row["lname"], "first" =&gt; $row["fname "] ); } echo json_encode( $arr ); ?&gt; </code></pre> <p><em>Sql for each selection:</em> [Professor]</p> <pre><code>SELECT pID, lname, fname FROM Professor WHERE CONCAT(lname,fname) LIKE '%". $keywords . "%'"; </code></pre> <p>[Department]</p> <pre><code>SELECT prefix, code FROM Department WHERE name LIKE '%". $keywords . "%'"; </code></pre> <p>[course]</p> <p>SELECT prefix, code FROM Course WHERE CONCAT(prefix,course) LIKE '%". $keywords . "%'";</p>
 

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