Home | Projects | Tutorials | Articles | live chat | Submit Project | Big Vote
 
Ajax Projects
.NET Frameworks
Java Frameworks
PHP Frameworks
Ruby Frameworks
Other Frameworks
Cool AJAX sites
Ajax Resources
Ajax Tools
JavaScript frameworks

 Home /  Tutorials / Ajax Autosuggest

Ajax Autosuggest





Ajax autosuggest script is supposed to help the visitor and present in real time some possible results based on their entered words/characters.

Read The Full Tutorial.
































Ajax autosuggest script is supposed to help the visitor and present in real time some possible results based on their entered words/characters.

<?php
    require_once('db.php');
    include('classes/stem.php');
    include('classes/cleaner.php');
    
    if( !empty ( $_POST['search'] ) ):
   
        $string = $_POST['search'];
        $main_url = 'http://www.roscripts.com/';
   
        $stemmer = new PorterStemmer;
        $stemmed_string = $stemmer->stem ( $string );
   
        $clean_string = new jSearchString();
        $stemmed_string = $clean_string->parseString ( $stemmed_string );       
       
        $new_string = '';
        foreach ( array_unique ( split ( " ",$stemmed_string ) ) as $array => $value )
        {
            if(strlen($value) >= 3)
            {
                $new_string .= ''.$value.' ';
            }
        }

        $new_string = substr ( $new_string,0, ( strLen ( $new_string ) -1 ) );
       
        if ( strlen ( $new_string ) > 3 ):
       
            $split_stemmed = split ( " ",$new_string );
               
                mysql_select_db($database);
            $sql = "SELECT DISTINCT COUNT(*) as occurences, title, subtitle FROM articles WHERE (";
                    
            while ( list ( $key,$val ) = each ( $split_stemmed ) )
            {
                      if( $val!='' && strlen ( $val ) > 0 )
                      {
                          $sql .= "((title LIKE '%".$val."%' OR subtitle LIKE '%".$val."%' OR content LIKE '%".$val."%')) OR";
                      }
            }
           
            $sql=substr ( $sql,0, ( strLen ( $sql )-3 ) );//this will eat the last OR
            $sql .= ") GROUP BY title ORDER BY occurences DESC LIMIT 10";
       
            $query = mysql_query($sql) or die ( mysql_error () );
            $row_sql = mysql_fetch_assoc ( $query );
            $total = mysql_num_rows ( $query );
             
            if($total>0):
   
                    echo '    <div class="entry">'."\n";
                echo '        <ul>'."\n";
                    while ( $row = mysql_fetch_assoc ( $query ) )
                    {               
                        echo '            <li>'."\n";
                        echo '                <a href="'.$main_url.'articles/show/'.$row['id'].'">'.$row['title'].''."\n";
                        echo '                <em>'.$row['subtitle'].'</em>'."\n";
                        echo '                <span>Added on 2007-06-03 by roScripts</span></a>'."\n";
                        echo '            </li>'."\n";               
                    }
                   
                echo '        </ul>'."\n";
                echo '    </div>'."\n";
            endif;
        endif;
    endif;   
?> 
AddThis Social Bookmark Button
Top Projects
MSN Web Messenger
MessengerFX
ebuddy
e-messenger
ILoveIM
You Tube
AJAX file upload
KoolIM.com
Meebo
Ajax.NET Professional
Tutorials
Simplify Ajax development with jQuery
Design DHTML without HTML or CSS
Loading content with jQuery AJAX - using a loading image
Simple AJAX is getting advanced
Creating a dropdown menu with jQuery and CSS
jQuery, JSON and ASP.NET
Ajax Menu Examples
AJAX and PHP Building Responsive Web Applications
jTemplates with jQuery, AJAX and Json
AJAX: Asynchronous Java + XML?