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 autoincrement
title varchar=255 ,

 

json.php file


  1. <html>

  2. <head></he

  3. <html>

  4. <head>

  5. <title>tutu</title>
  6. <link rel="stylesheet" href="js/easy-autocomplete.min.css"/>

  7. <script src="//code.jquery.com/jquery-1.11.2.min.js"></script>

  8. <script type="text/javascript" src="js/jquery.easy-autocomplete.min.js"></script>

  9. </head>

  10. <body>

  11. <h1>Auto complete plugin with php pdo and jquery</h1> 
  12. <input id="provider-json" />

  13. <script type="text/javascript">

  14.     var options = {
  15.     url: "json.php",
  16.     getValue: "jsondata",

  17.     list: {

  18.         match: {

  19.             enabled: true

  20.         }

  21.     }
  22. };

  23. $("#provider-json").easyAutocomplete(options);

  24. </script>

  25. </body
  26. </html>

json.php file



  1. <?php

  2.  

  3.  $dbhost = "localhost";

  4.  $dbuser = "root";

  5.  $dbpass = "";

  6.  $dbname = "autocomplete";

  7.  

  8.  try{

  9.   

  10.   $dbcon = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);

  11.   $dbcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

  12.   

  13.  }catch(PDOException $ex){

  14.   

  15.   die($ex->getMessage());

  16.  }
  17.  $sqlquery = "select * from autocomplete";

  18. $run = $dbcon->prepare($sqlquery);
  19. $run->execute();
  20. $out = array();

  21. while($row=$run->fetch(PDO::FETCH_ASSOC)) {

  22.     $out[]= array('jsondata'=>$row['title']);

  23. }

  24. echo json_encode($out);

  25. ?>

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

  1. <?Php
  2.     $dbhost = 'localhost';
  3.     $dbname = 'load';  
  4.     $dbuser = 'root';                  
  5.     $dbpass = ''; 
  6.     
  7.     try{
  8.         
  9.         $dbcon = new PDO("mysql:host={$dbhost};dbname={$dbname}",$dbuser,$dbpass);
  10.         $dbcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  11.         
  12.     }catch(PDOException $ex){
  13.         
  14.         die($ex->getMessage());
  15.     }
  16.     
  17. ?>

index.php

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>onlinestudy.bramento.com</title>
  6. <script type="text/javascript">
  7. $(document).ready(function() {
  8.     $("#results").load("getcat.php");  //using load() functions here 
  9.     
  10. });
  11. </script>
  12. </head>
  13. <h1> How we can load .php file using jquery.</h1>
  14. <div id="results"></div>
  15. <body>
  16. </body>
  17. </html>

 getcat.php

  1. <?php
  2.         require_once 'db.php';  
  3.         $stmt = $dbcon->prepare('SELECT * FROM categories');
  4.         $stmt->execute();
  5.         
  6.         while($row=$stmt->fetch(PDO::FETCH_ASSOC))
  7.         {
  8.             extract($row);
  9.             ?>         
  10.        <p> <?php echo $row['cat_title']; ?></p>
  11.             <?php
  12.         }
  13.         ?>

How to create page views counter with php pdo

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

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