www.webdeveloper.com
Results 1 to 3 of 3

Thread: Ajax search issue - Accurate results

  1. #1
    Join Date
    Mar 2013
    Posts
    4

    Ajax search issue - Accurate results

    Hello,

    I have a certain issue with my search engine. Basically the results are not retrived quite well from my database. Let's say that I want to search a certain thing, let's call it Arad. I fill the box with Ar and I should be getting words which start with Ar. However, the script is searching now through the whole word. I enter Ar and I get results this way: Bar, Car, Adversary, Afterward, Alarm. It basically retrieves me words which contain ar but I should be getting words which start with ar.

    Here is a snippet:
    Code:
    	$(function(){
    			// The autocomplete feature for the destinations
    			jQuery('#fromRoute').autocomplete({
    				source: '/ag/lib/ajax.php?action=getAutoComplete&direction=from&to_val='+encodeURIComponent($('#toRoute').val()),
    				select: function(a, b){
    					if(b.item.value=='Nothing found!'){
    						$(this).val(''); return false;
    						$('#toRoute').autocomplete('option','source','/ag/lib/ajax.php?action=getAutoComplete&direction=to&from_val='+encodeURIComponent($(this).val()));
    					}
    					$(this).val(b.item.value);
    					$('#toRoute').autocomplete('option','source','/ag/lib/ajax.php?action=getAutoComplete&direction=to&from_val='+encodeURIComponent($(this).val()));
    					getScheduleTable()
    				},
    				response: function(event, ui) {
    					if((ui.content.length==1) && (ui.content[0].value!='Nothing found!')){
    						$(this).val(ui.content[0].value);
    						$(this).autocomplete('close');
    						$('#toRoute').autocomplete('option','source','/ag/lib/ajax.php?action=getAutoComplete&direction=to&from_val='+encodeURIComponent($(this).val()));
    						getScheduleTable()
    					}
    				}
    			});
    			$('#toRoute').autocomplete({
    				source: '/ag/libs/ajax.php?action=getAutoComplete&direction=to&from_val='+encodeURIComponent($('#fromRoute').val()),
    				select: function(a, b){
    					if(b.item.value=='Nothing found!'){
    						$(this).val(''); return false;
    						$('#fromRoute').autocomplete('option','source','/ag/lib/ajax.php?action=getAutoComplete&direction=from&to_val='+encodeURIComponent($(this).val()));
    					}
    					$(this).val(b.item.value);
    					$('#fromRoute').autocomplete('option','source','/ag/lib/ajax.php?action=getAutoComplete&direction=from&to_val='+encodeURIComponent($(this).val()));
    					getScheduleTable()
    				},
    				response: function(event, ui) {
    					if((ui.content.length==1) && (ui.content[0].value!='Nothing found!')){
    						$(this).val(ui.content[0].value);
    						$(this).autocomplete('close');
    						$('#fromRoute').autocomplete('option','source','/ag/lib/ajax.php?action=getAutoComplete&direction=from&to_val='+encodeURIComponent($(this).val()));
    						getScheduleTable()
    					}
    				}
    				
    			});

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    that's a php question, not a js question. well, it's really a mysql question, but im sure the php folks won't mind helping you out.

    it depends on the code in ajax.php, and how they build the SQL statement.
    sounds like they are using like, you may just need to adjust the formula.

    make sure to sanitize all input that finds its way into a sql command...

  3. #3
    Join Date
    Nov 2010
    Posts
    1,086
    I thought it was a jQuery question - that's the default functionality for the jQuery autocomplete here's a fiddle (not mine) that overrides the default filtering function:
    http://jsfiddle.net/miroslav/yLdn3/light/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles