I have a mysql query in php, using match / against to filter results. Im trying to get a wildcard after $string so the next character can be anything. Help?
"SELECT * FROM $table WHERE MATCH (message) AGAINST('$string%' IN BOOLEAN MODE)"
Use *
instead of %
as a wildcard when using MATCH (...) AGAINST (...)
:
"SELECT * FROM $table WHERE MATCH (message) AGAINST('$string*' IN BOOLEAN MODE)"
Don't embed variables into double-quoted strings and you're set:
"SELECT * FROM " . $table . " WHERE MATCH (message) AGAINST ('" . $string . "%' IN BOOLEAN MODE)"
That being said, I can't confirm this is valid SQL. But at least it'll ensure your variable is expanded properly and if it doesn't work then it won't be because of PHP.
And just in case this reminder will be useful, nevar forget to escape data that goes into a query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With