简体   繁体   中英

Need help on modification to mySQL MATCH AGAINST query

I have a simple jQuery/PHP autocomplete text box that gets the matches from mySQL. In my case if a name in the DB is

Brand new iPhone and iPod case

and the $q is

iph

the textbox will not pop out the above product name for me to select it until I write the entire matching word.

With wildcards I get my expected result, but when $q is

iphone ipod

I will not get the above product name.

$q = $_GET["q"];
WHERE name LIKE '%$q%'

What I have now is this below and my question is if there is a way to have the result before write the full word AND also to support the iphone ipod issue.

$q = $_GET["q"];
$words = explode(" ", $q);
$all = mysql_real_escape_string(implode(" +",$words));
WHERE MATCH (name) AGAINST ('+" . $all . "' IN BOOLEAN MODE)
$all = mysql_real_escape_string(implode("* +",$words));


WHERE MATCH (name) AGAINST ('+" . $all . "*' IN BOOLEAN MODE)

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