mysql - How to search ignoring spaces between words? -
i want search names using search module ignoring white spaces .
ex: if want search name "a b zilva"
i want disply results on dropdown if type name "ab zilva".
currently search without space not working
$db = jfactory::getdbo(); $searchp=$_get["term"]; $searchp = str_replace(' ','%%', trim($searchp)); //$searchp= preg_split('/ /', $searchp); $query = $db -> getquery(true); $query="select * content title '%".$searchp."%'and categories_id=82 order title asc "; $db -> setquery($query); // load results list of associated arrays. $results = $db -> loadassoclist(); $json=array(); foreach ($results $json_result) { $json[] = array('value' => $json_result["title"], 'label' => $json_result["title"]); }
please advice .
update :
jquery.extend( jquery.ui.autocomplete.prototype, { _renderitem: function( ul, item ) { var term = this.element.val(), regex = new regexp( '(' + term + ')', 'gi' ); html = item.label.replace( regex , "<b>$&</b>" ); return jquery( "<li></li>" ) .data( "item.autocomplete", item ) .append( jquery("<a></a>").html(html) ) .appendto( ul ); } });
the problem code when replace space %%
, search like:
where title '%ab%%zilva%'
but won't match when title a b zilva
. need remove spaces both search string , column in database. this:
$searchp = str_replace(' ', '', $searchp);
and change sql to:
where replace(title, ' ', '') '%$searchp%'
for javascript highlighting, think need this:
var term = this.element.val().replace(/ /g, '').replace(/.(?=.)/g, '$& *'),
this create regular expression allows spaces between of characters in search string.
Comments
Post a Comment