Tagged: download autocomplete php

PHP Ajax Autocomplete Search from Database Example 0

PHP Ajax Autocomplete Search from Database Example

Today, We want to share with you PHP Ajax Autocomplete Search from Database Example.In this post we will show you MySQL Database Live Search with PHP and AJAX, hear for jQuery Autocomplete Search using PHP, MySQL and Ajax we will give you demo and example for implement.In this post, we will learn about Autocomplete Textbox using jQuery, PHP and MySQL with an example.

PHP Ajax Autocomplete Search from Database Example

There are the Following The simple About PHP Ajax Autocomplete Search from Database Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop Ajax Search Box in PHP and MySQL, so Creating Autocomplete for City Search Using PHP and MySQL Database for this example is following below.

Step 1: Create members table

CREATE TABLE IF NOT EXISTS `members` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `password` varchar(60) COLLATE utf8_unicode_ci NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (`id`),
  UNIQUE KEY `members_email_unique` (`email`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;

Step 2: Create index.php file

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>pakainfo.com - </title>
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
	<style type="text/css">
		.pakainfo{
			margin-top:20px;
		}
		#pakainfo_find{
			display: none;
		}
		.list-span3-list a{
			text-decoration: none !important;
		}
		.list-span3 li{
			cursor: pointer;
			padding: 4px 0px;
		}
		.list-span3{
			list-style-type: none;
    		background: #d4e8d7;
		}
		.list-span3 li:hover{
			color: white;
			background-color: #3d3d3d;
		}
	</style>
</head>
<body>
<div class="container">
	<h1 class="text-center pakainfo">Auto Complete Search using jQuery</h1>
	<div class="row justify-content-center pakainfo">
		<div class="col-sm-6">
			<form id="pakainfoFrm" method="POST" action="">
				<div class="input-span3 input-span3-lg">
				  	<input type="text" id="searchquery" name="searchquery" class="form-control" placeholder="Eneter Your Search Name" aria-describedby="basic-addon2">
				</div>
			</form>
			<ul class="list-span3" id="pakainfo_find"></ul>
		</div>
	</div>
	<a href="https://pakainfo.com/" target="_blank" alt="pakainfo" title="pakainfo">Free Download Example - Pakainfo.com</a>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
	//jQuery Autocomplete search using Serever side Get Data PHP, MySQLi, Ajax and jQuery
		//here HTML Form to generate suggestion on keyup
		$('#searchquery').keyup(function(e){
			e.preventDefault();
			var form = $('#pakainfoFrm').serialize();
			$.ajax({
				type: 'POST',
				url: 'get_membersList.php',
				data: form,
				dataType: 'json',
				success: function(response){
					if(response.error){
						$('#pakainfo_find').hide();
					}
					else{
						$('#pakainfo_find').show().html(response.data);
					}
				}
			});
		});
		//jQuery fill the input
		$(document).on('click', '.list-span3-list', function(e){
			e.preventDefault();
			$('#pakainfo_find').hide();
			var memberFname = $(this).data('memberFname');
			$('#searchquery').val(memberFname);
		});
	});
</script>
</body>
</html>

Step 3: Create get_membersList.php file

<?php
	if(isset($_POST['searchquery'])){
		$conn = new mysqli('localhost', 'root', 'root', 'atmiya_25');
		$datar_response = array('error' => false, 'data' => '');
 
		$searchquery = $_POST['searchquery'];
 
		if(empty($searchquery)){
			$datar_response['error'] = true;
		}else{
			$sql = "SELECT * FROM members WHERE name LIKE '%$searchquery%'";
			$sqlquery = $conn->query($sql);
 
			if($sqlquery->num_rows > 0){
				while($memberData = $sqlquery->fetch_assoc()){
					$datar_response['data'] .= "
						<li class='list-span3-list' data-memberFname='".$memberData['name']." ".$memberData['lastname']."'>".$memberData['name']." ".$memberData['lastname']."</li>
					";
				}
			}
			else{
				$datar_response['data'] = "
					<li class='list-span3-list'>No Any found data matches Members Records</li>
				";
			}
		}
 
		echo json_encode($datar_response);
	}
?>

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Ajax Autocomplete Search from Database Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Ajax Autocomplete Live Search Suggestion using PHP MySQL 0

Ajax Autocomplete Live Search Suggestion using PHP MySQL

Today, We want to share with you Ajax Autocomplete Live Search Suggestion using PHP MySQL.In this post we will show you PHP Ajax Autocomplete Search from Database Example, hear for Auto complete search with Ajax, jQuery, PHP and MYSQL we will give you demo and example for implement.In this post, we will learn about Search Suggestion Functionality with PHP and MySQL with an example.

Ajax Autocomplete Live Search Suggestion using PHP MySQL

There are the Following The simple About Ajax Autocomplete Live Search Suggestion using PHP MySQL Full Information With Example and source code.

As I will cover this Post with live Working example to develop Autocomplete Textbox using jQuery, PHP and MySQL, so the Autocomplete with PHP, MySQL and Jquery UI for this example is following below.

Step 1: HTML Interface

index.html

First of all, let’s simple create HTML an index.html file for Autocomplete or Search Suggestion.

<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Language" content="en-us">
    <title>Autocomplete Textbox using jQuery, PHP and MySQL - Pakainfo.com</title>
    <meta charset="utf-8">
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <script src="//netsh.pp.ua/upwork-demo/1/js/typeahead.js"></script>
    <style>
        h1 {
            font-size: 20px;
            color: #f5f5f5f;
        }

        .content {
            width: 80%;
            margin: 0 auto;
            margin-top: 60px;
        }

        .tt-hint,
        .city {
            border: 2px solid #c60000;
            border-radius: 10px 10px 10px 10px;
            font-size: 24px;
            height: 45px;
            line-height: 30px;
            outline: medium none;
            padding: 10px 12px;
            width: 500px;
        }

        .tt-dropdown-menu {
            width: 500px;
            margin-top: 5px;
            padding: 10px 12px;
            background-color: #fff;
            border: 1px solid #ccc;
            border: 1px solid rgba(0, 0, 0, 0.2);
            border-radius: 10px 10px 10px 10px;
            font-size: 110px;
            color: #111;
            background-color: #3d3d3d;
        }
    </style>
    <script>
        $(document).ready(function() {

            $('input.city').typeahead({
                name: 'city',
                remote: 'get_members.php?search=%SEARCH'

            });

        })
    </script>
</head>

<body>
    <div class="Pakainfo content">

        <form>
            <h1>Please type of the City or Zip code</h1>
            <input type="text" name="city" size="30" class="city" placeholder="Please Enter Your City or Country ZIP code">
        </form>
    </div>
</body>

</html>

Step 2: Serever Side Source code

get_members.php

And then I shall create a PHP Page mysql.php file which will all the aggregate Mysql Database query to MySQL DB as well as also give outpur response as type of the JSON. Serever Side Code for Creating Autocomplete or Search Suggestion Functionality with PHP and MySQL

<?php

//CREDENTIALS FOR Database
define ('DBSERVER', 'localhost');
define ('DBUSER', 'root');
define ('DBPASS','Mypassword');
define ('DBNAME','memberlist');

$connection = mysql_connect(DBSERVER, DBUSER, DBPASS) or die("Can't connect to server.");
$result = mysql_select_db(DBNAME) or die("Can't your select database.");

//CREATE Mysql search TO Database as wel as PUT RECEIVED DATA INTO PHP ASSOCIATIVE ARRAY
if (isset($_REQUEST['search'])) {
    $search = $_REQUEST['search'];
    $sql = mysql_query ("SELECT zip, city FROM zips WHERE city LIKE '%{$search}%' OR zip LIKE '%{$search}%'");
	$membersarray = array();
    while ($datamembers = mysql_fetch_array($sql)) {
        $membersarray[] = array (
            'label' => $datamembers['city'].', '.$datamembers['zip'],
            'value' => $datamembers['city'],
        );
    }
    //RETURN JSON ARRAY
    echo json_encode ($membersarray);
}

?>

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Ajax Autocomplete Live Search Suggestion using PHP MySQL.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.