Jquery select2 ajax autocomplete using PHP/MySQLi

Jquery select2 ajax autocomplete using PHP/MySQLi

In this Post We Will Explain About is Jquery select2 ajax autocomplete using PHP/MySQLi With Example and Demo.Welcome on Live24u.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Jquery select2 ajax autocomplete example with demo in PHP Example

In this post we will show you Best way to implement Simple select2 using PHP, MySQLi, AJAX and JQuery , hear for How to Create a jquery-ui Autocomplete Step by Step with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Also Read :   AngularJS Login with Session in PHP MySQLi

Jquery select2 ajax autocomplete using PHP

Jquery Plugin : select2 plugin is a very most famous and simple or very easy to intigrate jquery plugin, using jquery select2 plugin you can do some main thing like as a jquery select-option box with search means auto-complete like as, select option with some check box, and here call of the php page and get result json ajax auto-complete etc.

Include External Libs

<script src="1.9.1/jquery.js"></script>
<link href="4.0.3/css/select2.min.css" rel="stylesheet" />
<script src="/libs/select2/4.0.3/js/select2.min.js"></script>
<script src="script.js"></script>


<div style="width:600px;margin:5px auto;margin-top:40px;height:600px;">
  <select class="productName form-control" style="width:600px" name="productName"></select>


<script type="text/javascript">
        placeholder: 'Select an Products',
        ajax: {
          url: '/do_get_results.php',
          dataType: 'json',
          delay: 250, //delay time
          processResults: function (data) { //get result
            return {
				//return all the php json data
              results: data
          cache: true


define (DB_HOST, "SERVER_NAME");

//database connection
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);

$livesql = "SELECT products.id, products.name FROM products 
		WHERE name LIKE '%".$_GET['q']."%'
		LIMIT 8"; 
$dataresult = $mysqli->query($livesql);

$resultjson = [];
while($datarow = $dataresult->fetch_assoc()){
     $resultjson[] = ['id'=>$datarow['id'], 'text'=>$datarow['name']];
echo json_encode($resultjson);

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

Also Read :   PHP OOPS Dynamically Insert Update Delete MySQLi Query


I hope you have Got What is Autocomplete with PHP, MySQL and Jquery UI And how it works.I would Like to have FeedBack From My Blog(live24u.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(live24u.com) Are Most Always Welcome.