I am looking for a keyword search on my website and having a bit of difficulties
$q = "SELECT * from post WHERE post_k like '%".$_GET['s']."%'";
website url after search is website.com/?s=keyword
I am not getting fulltext searches. For example if I search for robin I can get results from batman because they both have n in the word. I am looking for a search that if I type robin I will only get results from robin.
Thanks
You need to use MATCH AGAINST
with FULLTEXT INDEX
.
CREATE FULLTEXT INDEX search_index ON post (post_k);
Then your query would be more like (Example using prepared statements with MySQLi):
$query = $mysqli->prepare("SELECT * FROM post WHERE MATCH(post_k) AGAINST(?)");
$query->bind_param('s', $_GET['s']);
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.