Sunday, 28 April 2013

Search suggestion using ajax,php and mysql

Create search engine with search suggestion like google using ajax,php and mysql.(search suggestion in php, how to show search suggestion using php and mysql,search. )

Step 1 : Create html text box (search.html )

         <title>search suggestion</title>
        <style type="text/css">
               #search_item ul li{display:block;}
        <script type="text/javascript">
               $('#search_item ul').click(function(event){
                      var data = $(;
                  <form action="" method="post"> 
                  <input type="text" id="search_box" name="name" />
                   <input type="button" value="Search" id="search_button"/>
               <div class="search_item" id="search_item">

Step 2 : Create database table

  `id` bigint(12) NOT NULL AUTO_INCREMENT,
  `name` text NOT NULL,
  PRIMARY KEY (`id`)
) ;

Step 3 : Create Ajax file ( ajax.js )

         var search=$("#search_box").val();
         var dataString="item="+search;                      
                cache: false,
                    $("#rr ul").html(response);

Step 4 : Create php file ( ajax.php )


        $keyword =preg_replace('/\s+/', '', $searchq);
        $keyword =str_split($keyword);
        $query = "SELECT name  FROM table1" . "WHERE name LIKE '%".$keyword['0']."%'";
              for ($i=1; $i<count($keyword); $i++) {
                    $query = $query."AND  name LIKE '%".$keyword[$i]."%'";
                   $result = mysql_query($query);
                      while($row = mysql_fetch_assoc($result)) {
                              echo "<li>".$row['name']."</li>";

Monday, 22 April 2013

Remove extra spaces from string in php

Removing the space into string using php.this problem facing many time by the php coder. i am trying to solve this problem here.remove extra space from string using php,remove space in php,how to hide extra space from string using php.

 Type 1 :  trim( ) Function

This function only remove space before and after the string
         $str="   This is only for test     ";
         echo trim($str);

// output
        This is only for test

Type 2 :  preg_replace( ) Function

This Function remove space between the string

     $str="This    is    only   for    test"; 
     $str = preg_replace("/\s+/"," ",$str);
        echo $str;
     This is only for test
if you like this please comment this 

Sunday, 21 April 2013

About Technology and Life

Technology has adversely affected the quality of life and work because it is used inappropriately. For example, large companies working on large projects will often utilize the telephone to coordinate efforts of team members rather than bringing people together in the same location.