Home » PHP Vue.js Live Search Box Using MySQL

PHP Vue.js Live Search Box Using MySQL

PHP Vue.js Live Search Box Using MySQL

In this Post We Will Explain About is PHP Vue.js Live Search Box Using MySQL 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 Live Search using Vue.js with PHP Example

In this post we will show you Best way to implement VueJS Ajax Live Search With PHP and MySQL, hear for VueJS Build Live Search Box Using PHP, MySQL And AJAX with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Read Also:  How to fix the "jQuery or $ not defined WordPress" Issue in WordPress?

PHP Vue.js Live Search Box Using MySQL

In this Example,First of all Add or Include External Libs Like as a(jQuery, css etc..), and then create a simple index.php or index.html page.After that crate a simple javascript file like as a index.js or main.js, It is also add your web-application First Header Part to some priority set.After that Include your relevant CSS Class.

Creating Simple Database

CREATE TABLE `users` (
  `userid` INT(11) NOT NULL AUTO_INCREMENT,
  `userfname` VARCHAR(30) NOT NULL,
  `userlname` VARCHAR(30) NOT NULL,
PRIMARY KEY(`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Inserting Data into our Database

INSERT INTO `users` (`userid`, `userfname`, `userlname`) VALUES
(1, 'krunal', 'sisodiya'),
(2, 'jaydeep', 'Gondaliya'),
(3, 'ankit', 'kathiriya'),
(4, 'chirag', 'Dethariya');

index.php



	<title>PHP Vue.js Live Search Box Using MySQL</title>
3.3.7/css/bootstrap.min.css
vue/2.5.10/vue.min.js
axios.min.js


<div id="mymain">
	<div class="container">
		<h1 class="page-header text-center"></h1>
		<div class="col-xl-8 col-xl-offset-2">
			<div class="row">
				<div class="col-xl-4 col-xl-offset-8">
					
				</div>
			</div>
			<div style="height:15px"></div>
			<table class="table table-bordered table-striped">
				<thead>
					<th>USER Firstname</th>
					<th>USER Lastname</th>
				</thead>
				<tbody>
 
						<tr>
							<td colspan="2" align="right">No user match your search</td>
						</tr>
 
					<tr>
						<td>{{ user.userfname }}</td>
						<td>{{ user.userlname }}</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
</div>



main.js

var main = new Vue({
	el: '#mymain',
	data:{
		users: [],
		search: {queryStr: ''},
		nouser: false
	},
 
	mounted: function(){
		this.fetchUsers();
	},
 
	methods:{
		checkSearch: function() {
			var queryStr = main.toFormData(main.search);
	   		axios.post('do_action.php?do_action=search', queryStr)
				.then(function(results){
					main.users = results.data.users;
 
					if(results.data.users == ''){
						main.nouser = true;
					}
					else{
						main.nouser = false;
					}
				});
       	},
 
       	fetchUsers: function(){
			axios.post('do_action.php')
				.then(function(results){
					main.users = results.data.users;
				});
       	},
 
		toFormData: function(obj){
			var liveForm = new FormData();
			for(var key in obj){
				liveForm.mainend(key, obj[key]);
			}
			return liveForm;
		},
 
	}
});

do_action.php

connect_error) {
    die("Connection failed: " . $db_con->connect_error);
}
 
$output = array('error' => false);
 
$do_action="show";
 
if(isset($_GET['do_action'])){
	$do_action=$_GET['do_action'];
}
 
if($do_action=='show'){
	$sql = "select * from users";
	$query = $db_con->query($sql);
	$users = array();
 
	while($data_row = $query->fetch_array()){
		array_push($users, $data_row);
	}
 
	$output['users'] = $users;
}
 
if($do_action=='search'){
	$queryStr=$_POST['queryStr'];
	$sql="select * from users where userfname like '%$queryStr%' or userlname like '%$queryStr%'";
	$query = $db_con->query($sql);
	$users = array();
 
	while($data_row = $query->fetch_array()){
		array_push($users, $data_row);
	}
 
	$output['users'] = $users;
}
 
$db_con->close();

//return simple json format and data display 
header("Content-type: mainlication/json");
echo json_encode($output);
die();
 
?>

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

Read Also:  Javascript Autocomplete Address Using PHP With Demo

Example

I hope you have Got What is How to Integrate live search in PHP and MySQL with VueJS 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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Laravel Live Search Example Tutorial From Scratch
  2. Read Also:  Ajax PHP MySQL Creating Autocomplete Search Suggestion
  3. Read Also:  PHP Highlight search matching text Results with Mysql
  4. Read Also:  MySQL Remove special characters from database
  5. Read Also:  PHP Autocomplete Textbox using jQuery Example
  6. Read Also:  react open new tab on button click
  7. Read Also:  Date Filter Using Angular Example with Demo
  8. Read Also:  AngularJS Search Auto Suggestion box with PHP MySQLi
  9. Read Also:  Laravel 5.7 database Multiple seeder Example
  10. Read Also:  Google Like Autosuggest Search Using PHP Ajax

Leave a Comment

Your email address will not be published. Required fields are marked *