mysql - stored with degree symbol, be able to search without, php SQL LIKE statement -


i'm haveing abit of trouble search function i've built.

i have column in mysql table called: title (utf8_swedish_ci)

this 2 titles out of around 20.000:

50° riesling réserve trocken   50° parallel riesling trocken 

is there somehow can make work user search 50 riesling or 50 parallel, without degree symbol?

my code:

$search = str_replace("\'","’", $_get['searchstring']); $search = htmlentities($search); $search = esc_sql($search); $search = trim($search); if(!empty($_get["searchstring"])){     $str .= "`title` '%".$search."%' , "; } 

sql statement (part of it, regarding this):

$res = $wpdb->get_results("select * searchtbl ".$str." order ".$sortby." ".$sort." limit 500"); 

as question: there "easy" way make user able search 50 riesling , find both items? (its relevant alot of titles not these two)

thanks in advance

you have multiple options, can combine achieve desired output.

  1. create field in table in store titles without specials characters, such ° , run serach on both columns or strip special characters seraches well. if have mysql v5.7.6 or newer, using generated columns ideal solution this.

  2. you can remove these special characters 'on fly', while searching in criteria. again, generated columns faster solution.

  3. use fulltext index , search. however, need reduce default minimum word length 2 , have play around collation file well. this topic contains more information on this.

  4. you can split search string words in php example using explode() , serach words not in single serach criteria, in separate ones.

the advantage of last 2 approaches would find both records if 50 riesling search criteria.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -