Ajax Autocomplete Search using jQuery with PHP MySQLi
In this Post We Will Explain About is Ajax Autocomplete Search using jQuery with PHP MySQLi With Example and Demo.Welcome on pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to jquery autocomplete multiple fields using jquery ajax php and mysqli Example
In this post we will show you Best way to implement Ajax Autocomplete textbox using jQuery, PHP and MySQLi, hear for Autocomplete search using jQuery Ajax with PHP MySQLi with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.
Creating simple Search Form
Here, I Make simple query search form where I search for a querystr, Make a new HTML file, name Like as index.html and simple copy paste the source codes below.
Autocomplete search using PHP, MySQLi, Ajax and jQuery .gst20{ margin-top:20px; } #live_search{ display: none; } .list-gpfrm-list a{ text-decoration: none !important; } .list-gpfrm li{ cursor: pointer; } .list-gpfrm li:hover{ color: white; background-color: #3d3d3d; }Auto Complete Search using jQuery
Creating simple jQuery Script
And then, I make simple jQuery script where I Add all simple main jquery functions and http request.create a new file, name Like as app.js and here copy paste the source codes below.
$(document).ready(function(){ //Autocomplete search using PHP, MySQLi, Ajax and jQuery //generate suggestion on keyup $('#querystr').keyup(function(e){ e.preventDefault(); var form = $('#liveForm').serialize(); $.ajax({ type: 'POST', url: 'do_search.php', data: form, dataType: 'json', success: function(response){ if(response.error){ $('#live_search').hide(); } else{ $('#live_search').show().html(response.data); } } }); }); //fill the input $(document).on('click', '.list-gpfrm-list', function(e){ e.preventDefault(); $('#live_search').hide(); var fullname = $(this).data('fullname'); $('#querystr').val(fullname); }); });
Creating simple Search Script
Lastly, I make the script that find or searches simple database from the inputted querystr,Male a new file, name it as do_search.php and paste the codes below.
false, 'data' => ''); $querystr = $_POST['querystr']; //check if querystr is empty if(empty($querystr)){ $results['error'] = true; } else{ //fetching data from mysql database via querystr $sql = "SELECT * FROM users WHERE username LIKE '%$querystr%' OR sirname LIKE '%$querystr%' OR nickname LIKE '%$querystr%'"; $sqlquery = $conn->query($sql); if($sqlquery->num_rows > 0){ while($ldata = $sqlquery->fetch_assoc()){ $results['data'] .= "
You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example
I hope you have Got What is Autocomplete search using jQuery Ajax with PHP MySQLi And how it works.I would Like to have FeedBack From My Blog(pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(pakainfo.com) Are Most Always Welcome.