I’m building a MySQL movie posters/fan art database driven by a PHP script. I created an autocomplete input field where the user searches for the movie title. Like all autocomplete fields work, as the user starts typing movie titles are displayed.
Now the MySQL query is the following:
SELECT posters FROM pictures WHERE pictures LIKE '$text%'
The above pattern matches every movie title that starts with the typed letter. As the dartabase contains aprox 10.000 movie titles the autocomplete feature has a delay when the user types the first letter. To speed up the search query within the autocomplete function I would like to use a pattern that matches at least TWO (or more) letters INSIDE the string and not only at the beginning of it.
For example, if the user types:
'pie'
the autocomplete function should display:
'American pie'
'American pie 2'
Using the MySQL wildcard ‘_’ (underscore) does not help. Is there a method to give the autocomplete function this feature?
Thank you
mysql is smart enoug to NOT try every line if the first check fails
also indexes with lengths help on this type of fields/query’s, for exampple so make one of length 2 and one of length 5 and one for the rest(if it is not too big)