I’d like to search a MySQL database to match keywords passed by the user. I heard that using LIKE is the fastest option but can’t find an example of a full simple query using LIKE in PHP code.
This is what I am tring:
$value = 'Fire';
$result = mysql_query("SELECT * FROM effects WHERE title LIKE 'value%'");
I know there is an row in the database with Fire as the title but the query is returning null.
Can someone please give me an example of how to perform a MySQL LIKE search or alternative to find rows by keyword(s).
Thank you.
You are missing
$before variablevalue.Your query should look like
Say there is title like
My Fire Effect. You don’t want this in search result? If you want to displayMy Fire Effectin result too then you should use%before $valueHope this helps you.
For Differences, see demo with live example
Note, first query in demo returns me 5 rows, however second query returns me 8 rows which is PERFECT.