简体   繁体   中英

mysql search with multiple keywords touching

$sql ="
        SELECT * FROM table

        WHERE $email_filter lower(table.synopsis) like '% $search_word_fix %'
        OR lower(table.sp_name) like '% $search_word_fix %'    
        GROUP by table.sp_name  
        ORDER BY table.grade DESC
        ";
    $re=mysql_query($sql);

so I have this simple sql query, if I search for 2 words for example: Hello World it returns results for both the word: hello. and results for the word: world I am trying to get it to return ONLY "hello word" if I use: where table.field ='$keyword' I get : no results. which I have phpmyadmin open and I know for a fact that there are results. any help is appreciated it.thank you

更改=的LIKE,=强制单词绝对

Try:

$sql ="
    SELECT * FROM table

    WHERE $email_filter lower(table.synopsis) REGEXP '[[:<:]]$search_word_fix[[:>:]]' = 1

    OR lower(table.sp_name) REGEXP '[[:<:]]$search_word_fix[[:>:]]' = 1
    GROUP by table.sp_name  
    ORDER BY table.grade DESC
    ";

Hope it helps

Try removing that % sign. so the like query looks like

like '$search_word_fix'
WHERE table.field LIKE '%Hello world%'

要么

WHERE table.field LIKE '%Hello%world%'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM