Mokey Nepal
THIS BLOG IS JUST FOR FREE INFORMATION,KNOWLEGES AND MORE. Here you can learn php , javascripts, bootstrap and soon.
Tuesday, April 18, 2017
Tuesday, March 28, 2017
How to make a autocomplete using jquery and php pdo with parsing json data from mysql
Here is the video tutorial for easy understanding
create mysql database autocomplete and create table autocomplete
Table structure:
id int value=12 , primary key autoincrementtitle varchar=255 ,
json.php file
<html>
<head></he
<html>
<head>
<title>tutu</title>- <link rel="stylesheet" href="js/easy-autocomplete.min.css"/>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="js/jquery.easy-autocomplete.min.js"></script>
</head>
<body>
<h1>Auto complete plugin with php pdo and jquery</h1>- <input id="provider-json" />
<script type="text/javascript">
var options = {- url: "json.php",
- getValue: "jsondata",
list: {
match: {
enabled: true
}
}- };
$("#provider-json").easyAutocomplete(options);
</script>
</body- </html>
json.php file
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "autocomplete";
try{
$dbcon = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
$dbcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $ex){
die($ex->getMessage());
}- $sqlquery = "select * from autocomplete";
$run = $dbcon->prepare($sqlquery);- $run->execute();
- $out = array();
while($row=$run->fetch(PDO::FETCH_ASSOC)) {
$out[]= array('jsondata'=>$row['title']);
}
echo json_encode($out);
?>
How can we load PHP file into DIV by jQuery?
In this tutorial, I am going to show you, How we can load .php file using jquery.
To load .php file, we simply use load() function to call php file in a div.
Here is the example how i load php file with jquery load() function
Database Name: `load`
Table structure for table `categories`
CREATE TABLE IF NOT EXISTS `categories` (`cat_id` int(100) NOT NULL,
`cat_title` varchar(500) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=latin1;
Dumping data for table `categories`
INSERT INTO `categories` (`cat_id`, `cat_title`) VALUES(3, 'What is html?'),
(4, 'What is css?'),
(5, 'What is php?\r\n'),
(10, 'What is linux?'),
(13, 'toit');
db.php
- <?Php
- $dbhost = 'localhost';
- $dbname = 'load';
- $dbuser = 'root';
- $dbpass = '';
- try{
- $dbcon = new PDO("mysql:host={$dbhost};dbname={$dbname}",$dbuser,$dbpass);
- $dbcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }catch(PDOException $ex){
- die($ex->getMessage());
- }
- ?>
index.php
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>onlinestudy.bramento.com</title>
- <script type="text/javascript">
- $(document).ready(function() {
- $("#results").load("getcat.php"); //using load() functions here
- });
- </script>
- </head>
- <h1> How we can load .php file using jquery.</h1>
- <div id="results"></div>
- <body>
- </body>
- </html>
getcat.php
- <?php
- require_once 'db.php';
- $stmt = $dbcon->prepare('SELECT * FROM categories');
- $stmt->execute();
- while($row=$stmt->fetch(PDO::FETCH_ASSOC))
- {
- extract($row);
- ?>
- <p> <?php echo $row['cat_title']; ?></p>
- <?php
- }
- ?>
How to Create Visitors counter by IP address in php pdo
This Tutorial is about How to Create Visitors counter by IP address in php pdo
First Create the database and name it as view and then create table
Table structure for table `visitors`
CREATE TABLE `visitors` (`id` int(11) NOT NULL,
`ip` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `visitors`
--
INSERT INTO `visitors` (`id`, `ip`) VALUES
(2, ''),
(3, ''),
(4, '::1'),
(5, '127.0.0.1');
<?Php
$dbhost = 'localhost';
$dbname = 'views';
$dbuser = 'root';
$dbpass = '';
try{
$dbcon = new PDO("mysql:host={$dbhost};dbname={$dbname}",$dbuser,$dbpass);
$dbcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $ex){
die($ex->getMessage());
}
?>
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$stmt = $dbcon->prepare("SELECT ip FROM visitors WHERE ip= '$ip'");
$stmt->execute();
$stmt1=$stmt->rowCount();
if ($stmt1==0) {
$stmt2 = $dbcon->prepare("INSERT INTO visitors(id, ip) VALUES(NULL, '$ip')");
$stmt2->execute();
}
$stmt = $dbcon->prepare('SELECT * FROM visitors');
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
extract($row);
echo $row['ip'];
}
?>
How to install laravel? xampp-window-php framework
How to install laravel? xampp-window-php framework
laravel download and setup link used in the video
laravel download and setup link used in the video
Worlds Best Amazing flute played on Resham Firiri by young guys
Amazing flute played on resham firiri by Nepali young guys
Amazing flute played on resham firiri by Nepali young guys
Amazing flute played on resham firiri by Nepali young guys
Worlds Best Amazing flute played on Resham Firiri by young guys
Subscribe to:
Posts (Atom)