The way this is set up, it will pull up results for multiple words in the $term variable.
I want it to pull up results that only match all words inside the $term span between main, secondary, sub columns.
Right now if $term is: “Hello World” it will pull results from the database:
id | main | secondary | sub 01 | statements | hello world | blah 02 | hello | what's up? | anything here 03 | life rocks | worldwide web | anything else here 04 | where in the world | she said hello | bleh
When what I would like is only results 01 and 04 to pull up because they include the full $term of Hello And World
Here’s my code. I’ve tried searching on here, and in Google. But in truth I don’t know what to look for. All I’ve found are full text searching documents, which I’m already doing here. I haven’t found any to say how to pull the exact result. (The sprintf is there because I guess I need that to be able to return it in a JSON response?
$query = sprintf("SELECT id, main, secondary, sub,
MATCH(main, secondary, sub) AGAINST('". $term ."' IN BOOLEAN MODE) AS score
FROM list_genres
WHERE MATCH (main, secondary, sub) AGAINST('". $term ."' IN BOOLEAN MODE)
ORDER BY score DESC LIMIT 15");
Your sentece is wrong, first sprintf() should receive as parameters, the terms, and use %s wherever you want to add it to the sql, also for multiple words you need to add a
+for each word.The code should be something like this: