Tagged: Autocomplete search using jQuery Ajax with PHP MySQLi Autocomplete search using jQuery Ajax with PHP MySQLi

Ajax Autocomplete Search using jQuery with PHP MySQLi 0

Ajax Autocomplete Search using jQuery with PHP MySQLi

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.



	
	<title>Autocomplete search using PHP, MySQLi, Ajax and jQuery</title>
	
	
		.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;
		}
	


<div class="container">
	<h1 class="text-center gst20">Auto Complete Search using jQuery</h1>
	<div class="row justify-content-center gst20">
		<div class="col-sm-6">
			<form id="liveForm" method="POST" action="">
				<div class="input-gpfrm input-gpfrm-lg">
				  	
				  	<div class="input-gpfrm-append">
				    	<button class="btn btn-outline-secondary" type="submit">Find or Search</button>
				  	</div>
				</div>
			</form>
			<ul class="list-gpfrm" id="live_search"></ul>
		</div>
	</div>
</div>
 




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'] .= "
						<li class='list-gpfrm-list'>".$ldata['username']." ".$ldata['sirname']."</li>
					";
				}
			}
			else{
				$results['data'] = "
					<li class='list-gpfrm-list'>No found data matches Records</li>
				";
			}
		}
 
		echo json_encode($results);
	}
?>

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

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.