Posted inTechnology / Ajax / Mysql / Mysqli / php / Programming / VueJs

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!.

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




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


USER Firstname USER Lastname
No user match your search
{{ user.userfname }} {{ user.userlname }}

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

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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

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

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype