jquery creates an ajax keyword data search implementation idea_jquery
WBOY
Release: 2016-05-16 17:41:28
Original
759 people have browsed it
In the process of web development, we often need to enter keywords on the front page to search for data. The search method we usually use is to display the search results on another page. This method is very useful for building high-performance websites. It’s not the most appropriate. Today I’d like to share with you how to use jQuery, MySQL and Ajax to create a simple and attractive Ajax search. This is the follow-up to Using jQuery to create a practical data transmission Modal pop-up form 》The second tutorial on the actual application of jquery projects. I hope everyone can use it flexibly according to their actual situation when developing projects
Click search to display all results by default
Search results displayed after entering A
Search results displayed after entering p
No relevant search term page found
Demo - Click the search button below to search for data
function checkValues($value) { // Use this function to check all these values to prevent sql Injection and cross-site scripting //Remove spaces or other characters at the beginning and end of the string $value = trim($value); // Stripslashes if (get_magic_quotes_gpc()) { //Remove the backslashes added by the addslashes() function, which is used to clean data retrieved from the database or HTML form. $value = stripslashes($value); } //Convert all <, > characters $value = strtr($value,array_flip(get_html_translation_table(HTML_ENTITIES)));
// Strip HTML tags $value = strip_tags($value);
// Quote value $value = mysql_real_escape_string($value); return $value; } include("dbcon.php");//Load the database connection file $rec = checkValues($_REQUEST['val']); //Get the table Content if($rec) { $sql = "select * from ajax_search where FirstName like '%$rec%' or LastName like '%$rec%' or Age like '%$rec% ' or Hometown like '%$rec%'";
} else { $sql = "select * from ajax_search"; } $rsd = mysql_query($sql);//Query this statement $total = mysql_num_rows($rsd);//Return the number of rows in the result set ?>