Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Sunday, 22 December 2013

Top PHP Framework Collection


Introduction

PHP Framework helps developers to create applications with speed and ease. Choosing best framework is very important for the successful development of the projects. A good PHP Framework must have following features
  • Must be compatible with latest PHP Version.
  • Must support MVC Structure.
  • Must support Multiple Databases.
  • Must has inbuilt template engine.
  • Must support caching and Validation.
  • Must support Ajax and useful modules.
Please Click here to see Details

Framework Collection and Features

Below is the collection of best PHP Frameworks for PHP developers.

Yii Framework

Yii is a high-performance PHP framework best for developing Web 2.0 applications. Yii helps Web developers build complex applications and deliver them on-time.
  • It's works efficiently with AJAX. It includes input validation, output filtering, SQL injection and Cross-site scripting prevention.
  • It's follows the MVC pattern, ensuring a clear separation of logic and presentation.
  • It's implement a skinning and theming mechanism that allows you to quickly switch the outlook of a Yii-power website.
  • Errors are handled and presented more nicely, and log messages can be categorized, filtered and routed to different destinations.
  • Every single method or property is clearly documented.
  • It's provide a set of intuitive and highly extensible code generation tools that can help you quickly generate the code you need for features such as form input, CRUD.
Yii Framework

CodeIgniter Framework

A Fully Baked PHP Framework. CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. If you're a developer who lives in the real world of shared hosting accounts and clients with deadlines, and if you're tired of ponderously large and thoroughly undocumented frameworks, then CodeIgniter might be a good fit.
  • a framework with a small footprint and exceptional performance.
  • It has clear, thorough documentation.
  • A framework with nearly zero configuration provide simple solutions to complexity
CodeIgniter Framework

CakePHP Framework

CakePHP makes building web applications simpler, faster and require less code.
  • Use code generation and scaffolding features to rapidly build prototypes.
  • No complicated XML or YAML files. Just setup your database and you're ready to bake.
  • The things you need are built-in. Translations, database access, caching, validation, authentication, and much more are all built into one of the original PHP MVC frameworks.
  • Instead of having to plan where things go, CakePHP comes with a set of conventions to guide you in developing your application.
  • It comes with built-in tools for input validation, CSRF protection, Form tampering protection, SQL injection prevention, and XSS prevention, helping you keep your application safe & secure.
CakePHP  Framework

Symfony Framework

Symfony is a PHP framework for web projects. Speed up the creation and maintenance of your PHP web applications. Replace the repetitive coding tasks by power, control and pleasure.
  • Easy to install and configure on most platforms with independent Database engine.
  • Simple to use and compliant with most web best practices and design patterns.
  • Easy to extend, allowing for integration with other vendor libraries.
Symfony Framework

Zend Framework

Zend Framework 2 is an open source framework for developing web applications and services using PHP 5.3+. Zend Framework 2 uses 100% object-oriented code and utilises most of the new features of PHP 5.3.
  • Building blocks that can be used piece by piece with other applications or frameworks.
  • All the cryptographic and secure coding tools you need to do things right.
  • Easy to adapt the framework to your needs.
  • A vibrant and active contributor and user base for getting help and giving back.
  • Engineered with performance tuning in mind.
  • A proven history of success running business critical and high-usage applications.
Zend Framework

Laravel Framework

The php framework for web artisans. Your life as a developer just got a whole lot easier.
  • Use simple Closures to respond to requests to your application. It couldn't be easier to get started building amazing applications.
  • Ships with the amazing Eloquent ORM and a great migration system. Works great on MySQL, Postgres, SQL Server, and SQLite.
  • Use native PHP or the light-weight Blade templating engine. Blade provides great template inheritance and is blazing fast. You'll love it.
  • Build huge enterprise applications, or simple JSON APIs. Write powerful controllers, or slim RESTful routes. Laravel is perfect for jobs of all sizes.
Laravel Framework

FuelPHP Framework

FuelPHP is a simple, flexible, community driven PHP 5.3+ framework, based on the best ideas of other frameworks, with a fresh start!
  • It is a MVC (Model-View-Controller) framework that was designed from the ground up to have full support for HMVC as part of its architecture.
  • It also supports a more router based approach where you might route directly to a closure which deals with the input uri, making the closure the controller and giving it control of further execution.
  • Security concerns have been front and center from the beginning. Out-of-the-box FuelPHP's Views will encode all your output to make it secure and prevent XSS attacks.
FuelPHP Framework

Conclusion

Now finally you have to choose the best framework which is suitable for your project. Hope you like this collection and find it very useful for choosing best PHP Framework for Development. For any query/suggestions please send message on our Facebook Page.Thanks :)

Thursday, 14 November 2013

Freebie Complete PHP Project Bootstrap PDO Sign-In Jquery UI Autocomplete Validation


It is a freebie complete project for PHP beginners using PDO (PHP Data Objects) queries, Bootstrap, MySQL Database, JQuery UI, Jquery Validation Plug-in with full source code. Bootstrap CSS framework is used along with JQuery UI Autocomplete. For password change match password option is also good for users they want to design a sign up form. In server stats insertion form only double number allowed using regular expression. Jquery Validation plug-in used in this freebie project which works fine in all major browsers. It is a complete system , you can improve this and share with others. Enjoy it!
Click here for Details

Tuesday, 5 November 2013

Easy Pagination with PDO in PHP plus Export to Excel Tutorial

This tutorial will show you how to make pagination easily with PDO (PHP Data Objects) in PHP. Export to Excel additional feature is also available in this tutorial.
  1. First we will create test database for pagination using below query.
    • --
      -- Below query create PaginationTestDb Database
      --
      CREATE DATABASE  `PaginationTestDb` ;
  2. Now we will create table in PaginationTestDb using below code. More sample data is available in CreateTableandDatasample.sql file which is available in Source Code.
    • CREATE TABLE IF NOT EXISTS `statstracker` (
        `SrNo` int(11) NOT NULL AUTO_INCREMENT,
        `ServerName` varchar(15) NOT NULL,
        `HiMemUti` double NOT NULL,
        `AvgMemUti` double NOT NULL,
        `HiCpuUti` double NOT NULL,
        `AvgCpuUti` double NOT NULL,
        `HiIOPerSec` double NOT NULL,
        `AvgIOPerSec` double NOT NULL,
        `HiDiskUsage` double NOT NULL,
        `AvgDsikUsage` double NOT NULL,
        `EntryBy` varchar(15) NOT NULL,
        `EntryDate` date NOT NULL,
        PRIMARY KEY (`SrNo`),
        UNIQUE KEY `SrNo` (`SrNo`)
      ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=15;
      -- Dumping data for table `statstracker`
      INSERT INTO `statstracker` (`SrNo`, `ServerName`, `HiMemUti`, `AvgMemUti`, `HiCpuUti`, `AvgCpuUti`, `HiIOPerSec`, `AvgIOPerSec`, `HiDiskUsage`, `AvgDsikUsage`, `EntryBy`, `EntryDate`) VALUES
      (1, '10.86.0.44', 98, 98, 98, 98, 98, 98, 98, 98, 'furqan.aziz', '2013-11-04'),
      (2, '10.86.0.75', 98, 96, 97, 90, 97, 94, 98, 90, 'furqan.aziz', '2013-11-05'),
      (3, '10.86.0.44', 95, 90, 92, 89, 93, 92, 94, 88, 'furqan.aziz', '2013-11-05'),
      (4, '10.86.0.66', 97, 97, 93, 88, 94, 92, 93, 93, 'furqan.aziz', '2013-11-05'),
      (5, '10.86.0.61', 12, 12, 12, 12, 12, 12, 12, 12, 'furqan.aziz', '2013-11-05'),
      (6, '10.86.0.44', 98, 98, 98, 98, 98, 98, 98, 98, 'furqan.aziz', '2013-11-04'),
      (7, '10.86.0.75', 98, 96, 97, 90, 97, 94, 98, 90, 'furqan.aziz', '2013-11-05'),
      (8, '10.86.0.44', 95, 90, 92, 89, 93, 92, 94, 88, 'furqan.aziz', '2013-11-05'),
      (9, '10.86.0.66', 97, 97, 93, 88, 94, 92, 93, 93, 'furqan.aziz', '2013-11-05'),
      (10, '10.86.0.61', 12, 12, 12, 12, 12, 12, 12, 12, 'furqan.aziz', '2013-11-05'),
      (11, '10.86.0.44', 98, 98, 98, 98, 98, 98, 98, 98, 'furqan.aziz', '2013-11-04'),
      (12, '10.86.0.75', 98, 96, 97, 90, 97, 94, 98, 90, 'furqan.aziz', '2013-11-05'),
      (13, '10.86.0.44', 95, 90, 92, 89, 93, 92, 94, 88, 'furqan.aziz', '2013-11-05'),
      (14, '10.86.0.66', 97, 97, 93, 88, 94, 92, 93, 93, 'furqan.aziz', '2013-11-05'),
      (15, '10.86.0.61', 12, 12, 12, 12, 12, 12, 12, 12, 'furqan.aziz', '2013-11-05');
  3. In this tutorial we have following files and resources. After you have download source code and unzip source, you will create database and table using above queries or using CreateTableandDatasample.sql. then you will put PAGINATIONPDO folder inside htdocs or www root and then test in browser.
    • CreateDatabase.txt contains create test database query.
    • CreateTableandDatasample.sql contains create table query and sample insert data query.
    • index.php is main file which has pagination code.
    • ExportToExcel.php is used to export all data in excel for specific user.
    • img folder contains export to excel PNG file.
    • css folder contains pagination.css file which have pagination style, table style and export to excel position style.
    • css folder contains Extra.css file having more styles Thanks to MIS ALGORITMOS.
  4. Here is index.php file code
    •  <!DOCTYPE html>
      <html lang="en">
        <head>
          <meta charset="utf-8">
          <title>Simple Pagination Demo using PDO Query</title>
              <!-- CSS File -->
          <link href="css/pagination.css" rel="stylesheet">
        </head>
       <body>
      <?php
       // mysql hostname
       $hostname = 'localhost';
       // mysql username
       $username = 'root';
       // mysql password
       $password = '';
       // Database Connection using PDO with try catch method. 
       try { $dbh = new PDO("mysql:host=$hostname;dbname=PaginationTestDb", $username, $password); }
       // In case of error PDO exception will show error message.
       catch(PDOException $e) {    echo $e->getMessage();    }
       // No. of adjacent pages shown on each side
       $adjacents = 2;
       // We will assign variable here for entry By. you can use your variables here.
       $EntryBy = "furqan.aziz";
       // We Will prepare SQL Query
          $STM = $dbh->prepare("SELECT ServerName FROM statstracker WHERE EntryBy = :EntryBy");
       // bind paramenters, Named paramenters alaways start with colon(:)
          $STM->bindParam(':EntryBy', $EntryBy);
       // For Executing prepared statement we will use below function
          $STM->execute();
       // Count no. of records
       $Records = $STM->rowCount();
       // Your File Name will be the same like your php page name which is index.php
       $targetpage = "index.php";
       // Below is setting for no. of records per page.
       $limit = 10; 
       $page = $_GET['page'];
       if($page) 
       //First Item to dipaly on this page
        $start = ($page - 1) * $limit;    
       else
       //if no page variable is given, set start to 0
        $start = 0;        
       // Get data using PDO prepare Query.
       $STM2 = $dbh->prepare("SELECT `SrNo`, `ServerName`, `HiMemUti`, `AvgMemUti`, `HiCpuUti`, `AvgCpuUti`, `HiIOPerSec`, `AvgIOPerSec`, `HiDiskUsage`, `AvgDsikUsage`, `EntryBy` FROM statstracker WHERE EntryBy = :EntryBy ORDER BY SrNo LIMIT $start, $limit");
       // bind paramenters, Named paramenters alaways start with colon(:)
          $STM2->bindParam(':EntryBy', $EntryBy);
       // For Executing prepared statement we will use below function
          $STM2->execute();
       // We will fetch records like this and use foreach loop to show multiple Results later in bottom of the page.
        $STMrecords = $STM2->fetchAll();
       // Setup page variables for display. If no page variable is given, default to 1.
       if ($page == 0) $page = 1;
       //previous page is page - 1     
       $prev = $page - 1;
       //next page is page + 1     
       $next = $page + 1;
       //lastpage is = total Records / items per page, rounded up.      
       $lastpage = ceil($Records/$limit);
       //last page minus 1 
       $lpm1 = $lastpage - 1;      
       //Now we apply our rules and draw the pagination object. We're actually saving the code to a variable in case we want to draw it more than once.
       $pagination = "";
       if($lastpage > 1)
       { 
        $pagination .= "<div class='pagination'>";
        //previous button
        if ($page > 1) 
         $pagination.= "<a href='$targetpage?page=$prev'>Previous</a>";
        else
         $pagination.= "<span class='disabled'>Previous</span>"; 
        
        //pages 
        if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
        { 
         for ($counter = 1; $counter <= $lastpage; $counter++)
         {
          if ($counter == $page)
           $pagination.= "<span class='current'>$counter</span>";
          else
           $pagination.= "<a href='$targetpage?page=$counter'>$counter</a>";     
         }
        }
        elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
        {
         //close to beginning; only hide later pages
         if($page < 1 + ($adjacents * 2))  
         {
          for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
          {
           if ($counter == $page)
            $pagination.= "<span class='current'>$counter</span>";
           else
            $pagination.= "<a href='$targetpage?page=$counter'>$counter</a>";     
          }
          $pagination.= "...";
          $pagination.= "<a href='$targetpage?page=$lpm1'>$lpm1</a>";
          $pagination.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";  
         }
         //in middle; hide some front and some back
         elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
         {
      
          $pagination.= "<a href='$targetpage?page=1'>1</a>";
          $pagination.= "<a href='$targetpage?page=2'>2</a>";
          $pagination.= "...";
          for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
          {
           if ($counter == $page)
            $pagination.= "<span class='current'>$counter</span>";
           else
            $pagination.= "<a href='$targetpage?page=$counter'>$counter</a>";     
          }
          $pagination.= "...";
          $pagination.= "<a href='$targetpage?page=$lpm1'>$lpm1</a>";
          $pagination.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";  
         }
         //close to end; only hide early pages
         else
         {
          $pagination.= "<a href='$targetpage?page=1'>1</a>";
          $pagination.= "<a href='$targetpage?page=2'>2</a>";
          $pagination.= "...";
          for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
          {
           if ($counter == $page)
            $pagination.= "<span class='current'>$counter</span>";
           else
            $pagination.= "<a href='$targetpage?page=$counter'>$counter</a>";     
          }
         }
        }
        
        //next button
        if ($page < $counter - 1) 
         $pagination.= "<a href='$targetpage?page=$next'>Next</a>";
        else
         $pagination.= "<span class='disabled'>Next</span>";
        $pagination.= "</div>\n";  
       }
       //Below is a start of table in which we will show records using foreach loop.
       echo "<table class='mytableP'>";
       // For Exporting Records to Excel we will send $EntryBy in link and will gate it on ExportToExcel page for stats for this user. 
       echo"<tr><th th colspan=11>Simple Pagination Demo using PDO Quries</div></th></tr>";
       echo"<a href='ExportToExcel.php?val=$EntryBy' target=_blank><img src='img/e2e.png' alt='Export To Excel' border='' class='e2e' /></a>";
       echo"<tr><th>Sr#</th><th>Server</th><th>Hi Memory Utilization</th><th>Avg Memory Utilization</th><th>Hi CPU Utilization</th><th>Avg CPU Utilization</th><th>Hi I/O Utilization</th><th>Avg I/O Utilization</th><th>Hi Disk Usage</th><th>Avg Disk Usage</th><th>By</th></tr>";
          // We use foreach loop here to echo records.
       foreach($STMrecords as $r)
              {
         echo "<tr>";
            echo "<td>" .$r[0] ."</td>";
               echo "<td>" .$r[1] ."</td>";
            echo "<td>" .$r[2] ."</td>";
            echo "<td>" .$r[3] ."</td>";
            echo "<td>" .$r[4] ."</td>";
            echo "<td>" .$r[5] ."</td>";
            echo "<td>" .$r[6] ."</td>";
            echo "<td>" .$r[7] ."</td>";
            echo "<td>" .$r[8] ."</td>";
            echo "<td>" .$r[9] ."</td>";
            echo "<td>" .$r[10] ."</td>";
          echo "</tr>";  
        }
       echo "</table>";
       // For showing pagination below the table we will echo $pagination here after </table>. For showing above the table we will echo $pagination before <table>
       echo $pagination;
       // Closing MySQL database connection   
          $dbh = null;
       ?>
        </body>
      </html> 
      
  5. Below is the css Style which is used for pagination.
    • div.pagination {text-align:center;margin:3px;padding:3px;}
      div.pagination a {margin-right:2px;border:1px solid #2C2C2C;text-decoration:none;color:#fff;background:#2C2C2C;padding:2px 5px;}
      div.pagination a:hover,div.pagination a:active {border:1px solid #AAD83E;color:#FFF;background:#AAD83E;}
      div.pagination span.current {margin-right:2px;border:1px solid #AAD83E;font-weight:700;background:#AAD83E;color:#FFF;padding:2px 5px;}
      div.pagination span.disabled {margin-right:2px;border:1px solid #f3f3f3;color:#ccc;padding:2px 5px;}
  6. For table we used below style code
    • .mytableP {border:none;width:100%;color:#666;margin:0;padding:0;}
      .mytableP th {font:bold 11px Calibri,Cambria,Verdana, Arial;color:#FFFFFF;border-right:1px solid #C1DAD7;border-bottom:1px solid #C1DAD7;border-top:1px solid #C1DAD7;letter-spacing:1px;text-transform:uppercase;text-align:left;background:#99CC33 repeat;padding:2px 2px 2px 3px;}
      .mytableP td {border-right:1px solid #CCC;border-bottom:1px solid #CCC;border-top:1px solid #CCC;border-left:1px solid #CCC;font:12px Calibri,Cambria,Verdana, Arial;color:#333;padding:2px 2px 2px 3px;}
  7. For showing Export to Excel icon in right bottom of the page.
    • .e2e { position:fixed; bottom:0; right:0;}
For Export to Excel File please check source file and read comments inside. This tutorial is based on phpeasystep tutorial which is written using mysql_query (deprecated function). I used PDO (PHP Data Objects ) and also provide export to excel option for this along with table style. For More Tutorials please visit http://crewow.com/

Monday, 28 October 2013

PHP PDO to Connect MySQL Database Tutorial

This tutorial will show you how to connect to MySQL Database using PDO (PHP Data Objects) which defines a lightweight, consistent interface for accessing databases in PHP.

Website : Crewow Website




  1. First we will create sample table. Below is a code for Sample MySQL table named category, you can copy it and paste it in your query window inside database say shopdb and run the query to create table.
    • --
      -- Table structure for table `category`
      --
      CREATE TABLE IF NOT EXISTS `category` (
        `SrNo` int(11) NOT NULL AUTO_INCREMENT,
        `Category` varchar(50) NOT NULL,
        `SubCategory` varchar(100) NOT NULL,
        PRIMARY KEY (`SrNo`)
      ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ;
      --
      -- Dumping data for table `category`
      --
      INSERT INTO `category` (`SrNo`, `Category`, `SubCategory`) VALUES
      (1, 'Electronics', 'Mobile'),
      (2, 'Electronics', 'Tablet'),
      (3, 'Electronics', 'IPad'),
      (4, 'Electronics', 'ITab'),
      (5, 'Electronics', 'Television'),
      (6, 'Electronics', 'Camera'),
      (7, 'Electronics', 'Laptop'),
      (8, 'Electronics', 'LCD'),
      (9, 'Electronics', 'Computer'),
      (10, 'Books', 'Magazines'),
      (11, 'Books', 'Journals'),
      (12, 'Books', 'Course Books'),
      (13, 'Garments', 'Kids Clothes');
  2. Now its time to connect to MySQL Database using PHP Data Objects. Create new PHP File and write following lines for connection to MySQL Database.
    • <?php
      // mysql hostname
      $hostname = 'localhost';
      // mysql username
      $username = 'username';
      // mysql password
      $password = 'password';
      // Database Connection using PDO
      $dbh = new PDO("mysql:host=$hostname;dbname=shopdb", $username, $password);
      // $dbh is a Database Handle
      // new is to create PDO Object
      // mysql is a Database type
      // host=$hostname;dbname=shopdb",$username,$password is a connection string
      // Closing MySQL database connection
          $dbh = null;
      ?>
  3. If there are any connection errors, a PDOException object will be thrown. You can catch the exception if you want to handle the error condition. we will use try/catch statement.
    • <?php
      // mysql hostname
      $hostname = 'localhost';
      // mysql username
      $username = 'username';
      // mysql password
      $password = 'password';
      // Database Connection using PDO
      try {
      $dbh = new PDO("mysql:host=$hostname;dbname=shopdb", $username, $password);
      // Closing MySQL database connection
          $dbh = null;
          }
      catch(PDOException $e)
          {
          echo $e->getMessage();
          }
      //If we will not use catch statement, then in case of error zend engine terminate the script and display a back trace. This back trace will likely reveal the full database connection details, including the username and password.  
      ?>
  4. The connection remains active for the lifetime of that PDO object. To close the connection, you will assign NULL to the variable($dbh) that holds the object.
    • <?php
      // Closing MySQL database connection
          $dbh = null;  
      ?>
  5. Now we will Select data from MYSQL Database using prepared statement. These statements helps to protect from SQL Injection. There are two methods to use prepared statements. one is named and second in unnamed. we will use one of them here.
    • <?php
      // mysql hostname
      $hostname = 'localhost';
      // mysql username
      $username = 'username';
      // mysql password
      $password = 'password';
      // Database Connection using PDO
      try {
      $dbh = new PDO("mysql:host=$hostname;dbname=shopdb", $username, $password);
      // Define Variables
          $SrNo = 6;
          $Category = 'Electronics';
      // We Will prepare SQL Query
          $STM = $dbh->prepare("SELECT * FROM category WHERE SrNo = :SrNo AND Category = :Category");
      // bind paramenters, Named paramenters alaways start with colon(:)
          $STM->bindParam(':SrNo', $SrNo);
          $STM->bindParam(':Category', $Category);
      // For Executing prepared statement we will use below function
          $STM->execute();
      // we will fetch records like this and use foreach loop to show multiple Results
          $STMrecords = $STM->fetchAll();
          foreach($STMrecords as $row)
              {
              echo $row['SrNo'].'-'.$row['Category'].'-'.$row['SubCategory'];
              }
      // Closing MySQL database connection   
          $dbh = null;
          }
      catch(PDOException $e)
          {
          echo $e->getMessage();
          }  
      ?>
You can also check Connections and Connection management for more details about PDO Connection.

Friday, 18 October 2013

PHP-MySQL Ajax Jquery-UI Autocomplete in Bootstrap Tutorial


This tutorial will show you how to use Jquery UI Autocomplete in Bootsrap via PHP, MySQL and AJAX. You can use it anywhere else too easily.
  1. You will learn to make Jquery UI autocomplete working in Bootstrap via PHP, MySQL and Ajax.
  2. First create a simple form using below code or you can use your own search code. Please note id of input is searchg which will use later.
    • <form  class="navbar-form pull-left">
      <input class="span4" id="searchg" type="text" placeholder="Search">
      <button class="btn" type="button">Search</button>
      </form>
      
  3. Now Download JQuery UI from here and unzip it and put it in assets folder of bootstrap or anywhere you want. and put following lines before the </body> tag
    • <!--Jquery UI required links-->
      <script src="assets/js/jquery.js"></script>
      <script src="assets/ui/jquery.ui.core.js"></script>
      <script src="assets/ui/jquery.ui.widget.js"></script>
      <script src="assets/ui/jquery.ui.position.js"></script>
      <script src="assets/ui/jquery.ui.autocomplete.js"></script>
  4. Now put following Jquery UI css link before the </head> tag.
    • <!--Jquery UI css link-->
      <link rel="stylesheet" href="assets/ui/themes/ui-darkness/jquery.ui.all.css">
      
  5. Under Jquery UI required links you will write following code for showing autocomplete on input. We will get data from php page Get_Categories.php using JSON and use searchg id.
    • <script type="text/javascript">
      $(document).ready(function()
      {
                $.ajax({
                     url: 'Get_Categories.php',
                     type: 'POST',
                     dataType: 'json',
                     success: function(data){
                           $('#searchg').autocomplete(
                           {
                                 source: data,
                                 minLength: 1   
                           });
                     }
                });  
      });
      </script>
  6. Now on Get_Categories.php page you will write following code to get results from database and output JSON String.
    • <?php
      /*** mysql hostname ***/
      $hostname = 'localhost';
      /*** mysql username ***/
      $username = 'username';
      /*** mysql password ***/
      $password = 'password';
      // Database Connection
      $dbh = new PDO("mysql:host=$hostname;dbname=mysql", $username, $password);
      // Query to get the usable locations
          $locale = $_GET['term'];
      $sql = "SELECT DISTINCT Category FROM `category` WHERE `Category` LIKE '%$locale%'";
      // Deifne array for products
       $Product_array = array();
         foreach ($dbh->query($sql) as $row)
              {
              $result = $row[0];
         // use arrray_push to store results
        array_push($Product_array, $result);
              }
      // put files in $jason and then echo it for getting in your page using Ajax.        
      $json = json_encode($Product_array);
      echo $json; 
      ?>
  7. Below is a code for MySQL Table, you can copy it and paste it in your query window inside database.
    • --
      -- Table structure for table `category`
      --
      CREATE TABLE IF NOT EXISTS `category` (
        `SrNo` int(11) NOT NULL AUTO_INCREMENT,
        `Category` varchar(50) NOT NULL,
        `SubCategory` varchar(100) NOT NULL,
        PRIMARY KEY (`SrNo`)
      ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ;
      --
      -- Dumping data for table `category`
      --
      INSERT INTO `category` (`SrNo`, `Category`, `SubCategory`) VALUES
      (1, 'Electronics', 'Mobile'),
      (2, 'Electronics', 'Tablet'),
      (3, 'Electronics', 'IPad'),
      (4, 'Electronics', 'ITab'),
      (5, 'Electronics', 'Television'),
      (6, 'Electronics', 'Camera'),
      (7, 'Electronics', 'Laptop'),
      (8, 'Electronics', 'LCD'),
      (9, 'Electronics', 'Computer'),
      (10, 'Books', 'Magazines'),
      (11, 'Books', 'Journals'),
      (12, 'Books', 'Course Books'),
      (13, 'Garments', 'Kids Clothes');
Above tutorial is very useful for making autocomple function in web pages. You can also use some features of this tutorials. For more information please visit Crewow Website