Scriptaculous Autocomplete from Database

Scriptaculous Autocomplete from Database

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
1,219 views

An Ajax autosuggest script is supposed to help the visitor and present in real time (as they type) some possible results based on their entered words/characters.In my opinion, this is a great feature to enhance the user experience.It’s very easy to build an autocomplete form using scriptaculous and prototype.You just need one line of javascriptnew Ajax.Autocompleter(id_of_text_field, id_of_div_to_populate, url, options);

.
.
.

Complex Code for Managed PHP Search Engine:

< ?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;
?>


Demo: http://www.roscripts.com/uploads/articles/153

Download:http://www.roscripts.com/login/index/attachments/download/154/3

Source: http://www.roscripts.com/Ajax_autosuggest_autocomplete_from_database-154.html

http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/stumbleupon_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/delicious_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/blinklist_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/furl_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/technorati_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/magnolia_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/google_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/myspace_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/facebook_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/sphinn_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/mixx_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/twitter_32.png

Related Listings:

  1. Ajax Autocomplete Script using jQuery This tutorial for the auto completer applications i have seen...
  2. Mootools-Ajax Contact Form Ajax can be very intimidating if you know very little...
  3. jQuery Plugin: Tokenizing Autocomplete Text Entry This is a jQuery plugin to allow users to select...
  4. Autocomplete TextboxList Script Extend TextboxList to add closing functionality via a link added...
  5. Search Autocomplete with .NET I am working on a rich content app for one...

Do you like this post?

Email:     

Tags: , , , , , , , , , , , , , , , , , , , , ,

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment



Web Design & CSS (Templates) - TOP.ORG