Here we are going to look into jquery ui auto complete with mysql database data.Here i am going to expalin the files and functionalities for doing these operations

index.php

<!doctype html>
<html lang="en">
 <head>
 <link rel="stylesheet" type="text/css" href="css/jquery-ui.css">

<style>
 .ui-autocomplete { 
 overflow-y: scroll !important; 
 overflow-x: hidden;
 }
 .ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {
 background:none;
 border: none;
 color: #000000;
 font-weight: bold;
 background-image: none;
 }
 input.wait {
 background: url("img/loader.gif") no-repeat scroll right center rgba(0, 0, 0, 0.01);
 }
 #txt-box {
 background: none repeat scroll 0 0 #EAEEEF;
 border: 1px solid #CCCCCC;
 border-radius: 3px;
 height: 35px;
 margin: 0 0 10px;
 padding: 5px;
 margin-bottom: 0;
 }
 </style>

 <script src="js/jquery.min.js"></script>
 <script src="js/jquery-ui.min.js"></script>
 </head>
 <body class="sidebar_hidden side_fixed" oncontextmenu="return false;">
 <input type="text" placeholder="Search" id="txt-box" class="form-control">
 <span class="warning-msg"></span>
 <script type="text/javascript" src="js/script.js"></script>
 </body>
</html>

in index.php we just include the jquery and jquery ui  js and css files and add a text box for doing the auto complete. Also included script.js for doing the autocomplete operation

script.js

$(document).ready(function () {
    $.ajax({
        url: 'get_values.php',
        dataType: 'json',
        cache: false,
        data: {getVal: 'name'},
        success: function (data) {
            if (data) {
                $('#txt-box').autocomplete({
                    search: function (event, ui) {
                        $(this).removeClass("wait");
                    },
                    responce: function (event, ui) {
                        $(this).removeClass("wait");
                    },
                    source: function (request, response) {
                        var matches = $.map(data, function (tag) {
                            if (tag.toUpperCase().indexOf(request.term.toUpperCase()) === 0) {
                                return tag;
                            }
                        });
                        if (matches.length == 0) {
                            $("#txt-box").val("");
                            $(".warning-msg").html("No Results Found");
                            $(".warning-msg").css({color: "red"});
                        } else {
                            $(".warning-msg").html("");
                        }
                        response(matches);
                    },
                    select: function (event, ui) {
                        // here we can get the seleted value of the auto complete
                        //alert(ui.item.value);
                    }
                }).data("ui-autocomplete")._renderItem = function (ul, item) {
                    var newText = String(item.value).replace(
                            new RegExp(this.term, "gi"),
                            "<span class='ui-state-highlight'>$&amp;</span>");
                    return $("<li></li>")
                            .data("item.autocomplete", item)
                            .append("<a>" + newText + "</a>")
                            .appendTo(ul);
                };
            }
        }
    });
});

In the above script first we get all the names in a json format from the database using ajax from the get_values.php file.In the success function we use the auto complete UI function for the text box.

get_values.php

<?php $con = mysql_connect("localhost", "root", "123456"); mysql_select_db("auto_complete"); if (isset($_GET['getVal'])) { $sql = "SELECT DISTINCT name FROM `auto_complete`"; $res = mysql_query($sql); $name_array = array(); while ($row = mysql_fetch_array($res)) { array_push($name_array, $row['name']); } $json = json_encode($name_array); echo $json; } ?>
 

You can download the files from the following link

autocomplete.zip

For using the script do the following steps:

1) Create the auto_complete db and upload the sql file into that db

2) Change the hostname, username and password for the mysql connection in the get_values.php file

SSH and SCP

Posted: October 10, 2014 in linux
Tags: , ,

SSH

ssh is a Secure Shell which is mainly used to establish a secure connecftion. We can login using ssh for accessing the

server. we can use the following command for login through ssh

ssh {username}@{hostname}

Login with different port

The default ssh port is 22. But some of the servers will have different port for ssh. We can use the following command
for logging in using different port

ssh -l {username} -p {portnumber} {hostname or ip}

here “l” refered as login name

and “p” for mentioning the port

SCP

SCP is nothing but the “Secure Copy” which used to transfer the files from one sytem(or)server to another server. For transfering the files from one server to another(i.e upload)

scp {source_file} {user_name}@{host_name}:{destination_folder}

for downloding the files from another server we have to use the following command

scp {user_name}@{host_name}:{path_of_the_file}/{file_to_download} ./

For different port we have to follow the same think like ssh

scp -p {port_number} {file_to_transfer} {user_name}@{host_name}:{destination_folder}

 

Import and export mysql db in command line

Posted: October 10, 2014 in Mysql
Tags:

Importing sql data

For importing large data through phpmyadmin we have to change some setting in the php.ini. Instead of that we can directly import the sql files using command line. There are two ways to do that.

Method 1

First goto the folder where the sql file you have (or) you have to mention the path of that file

mysql -h{hostname} -u{username} -p{password} {db_name} < import.sql

Method 2

First goto the folder where the sql file you have and then type the following command for log in to the mysql

 mysql -h localhost -u root -p{password} 

You will get into the mysql monitor. There you have run the following queries

First select database where you have to import the sql file

i.e.,

 mysql> use {database_name}; 

and then run the following query to import sql file

 mysql> source {sql_file}; 

Export

For export you have to use the following command

 mysqldump -h{hostname} -u{username} -p{password} {db_name} > {path to export}/{export.sql} 

 

Linux Commands

Posted: October 7, 2014 in linux
Tags:

Here we are going to look into some commonly using linux commands

Creating directory

For creating the folder we have to use mkdir. i.e.,

 mkdir folder_name 

Creating file:

For creating the folder we have to use touch i.e.,

 touch file_name 

Change Directory

Both of the following commands are used to change the current to previous directory

 cd ../ 

or

 cd .. 

the below command will change the directory to root directory

 cd / 

Rename or Move

For renaming the file or for moving the file from one directory to another directory we have to use “mv” command

i.e.,

for rename move file with different name in the same working directory

 mv source_file destination_file 

for moving file from one directory to another dirctory

 mv source_file destination_foler/destination_file 

Remove

For removing files are folders in linux we will use rm command

for removing files we have to use the following command

 rm filename 

for removing folders we have to add -r with the rm command for removing directories and their contents recursively

i.e.,

 rm -r folder_name 

Copy

For copying files we will use cp command

for copy the files

 cp test destination_folder/test 

for copy the folders we have to add -r with cp

 cp -r folder_name destination_folder/folder_name 

Find

For find the files are folders we have to use find command

 find -name "name of the file/folder" 

if you want to specify directory or file please use the following command

For file

 find -name "name of the file" -type f 

For Dierctory

 find -name "name of the directory" -type d 

Permissions

For giving permisson we have to use the chmod command

 chmod 777 file_name 

Here the each 7 have three different access that is

4 for read

2 for write

and

1 for execute
the 777 is for three different users i.e.,

first 7 is for owner

second 7 for group users

third 7 for end users (all the other users)

Routes in laravel

Posted: October 7, 2014 in laravel, php
Tags: ,

Laravel is having great feature for the nice urls. We can use the controllers and functions for custom urls

ex:

 Route::get('sample/getdata/{id}', array('uses' => 'controllername@functionname')); 

In the above routing concept if we give

 www.sample.com/sample/getdata/25

it will point to the controller function like

class controllername extends BaseController
{
public function functionname($id = null) {

}
}

from the above controller function we can get the id value as parameter
Here we are going to look into the function to get the submitted values inside the controller function

Route::match(array('GET', 'POST'), 'submit/submiturl', array('uses' => 'SubmitController@submitfunction'));

in the above code if  we submitting the values to a url like

http;//www.sample.com/submit/submiturl

and we can get the values in the function submitfunction inside the SubmitController

i.e.,

class SubmitController extends BaseController
{
public function submitfunction() {
$submitedData = Input::get();
}
}
} 

the Input::get(); function is for getting the submitted post value

Here we have to think about another thing.If we are submitting a value to the url which may or may not have the parameter.
For that we have to use the following code

Route::match(array('GET', 'POST'), 'submitted/submitfunction/{id?}', array('uses' => 'SubmitController@submitFunction'));

Cookie in laravel

Posted: October 7, 2014 in Cookie, laravel, php
Tags: , ,

Get cookie

For getting cookie in laravel use the following syntax

$cookie = Cookie::get('cookie_name');

Set cookie

For set a cookie we can use the following functon

Cookie::queue("cookie_name", "value");;

Redis with laravel

Posted: October 7, 2014 in laravel, Redis
Tags: , ,

Redis

Redis is an open source, advanced key-value store. Which is mainly using for the cache purpose and its having Strings, Lists, Sets and Hashes datatypes.We can store the data into the redis and we can fetch it when we want to use.

For using the redis first we have to install redis in our system. Please refer the following url for installing redis in the system

Redis installation

Redis in laravel

Laravel is having the support for using the redis with laravel. For that we have to follow the following steps

For establising redis connection first we have to configure the redis in app/config/database.php

i.e.,

 
'redis' => array(
    'cluster' => false,
    'default' => array(
    'host' => '127.0.0.1',
    'port' => 6379,
    ),
 )

In the above configuration the cluster is using for the large data with multiple access. If we are using small amount of data we can assign cluster false. Also redis cluster in alpha stage.

and host we have to mention host to establish redis connection and default port of redis is ‘6379’

For establishing the redis connection. We have to use the following code

Establish redis connection

 
$this->redis = Redis::connection();

Check the redis server availability using Exception Handler

The following code will check whether connection available or not if not it will through the exception error

 
try {
 $this->redis->ping();
 } catch (Exception $e) {
 // exception error
 }

Set redis value

For setting redis value we have to use the following code. If we want to store array values we have to serialise it. Because array is php data type. Redis will not aware of php array variable type

 
$this->redis->set("redis_name", serialize($newArr));

Get redis value

 
$this->redis->get("redis_name");