When you say this:
Code: Select all
$query = "SELECT film_id, film_title, film_actors, film_description, film_year, film_location, film_backup FROM films WHERE (film_title LIKE '%$trimmed_title%' OR film_actors LIKE'%$trimmed_name%' OR film_year LIKE'%$trimmed_year%') ORDER BY film_title";
What are the values of: $trimmed_title, $trimmed_name , and $trimmed_year?
You say you used the term "fifth" in this, and it returns all three. If that't the trimmed_title value, then your query evaluates to:
Code: Select all
$query = "SELECT film_id, film_title, film_actors, film_description, film_year, film_location, film_backup FROM films WHERE (film_title LIKE '%$fifth%' OR film_actors LIKE'%%' OR film_year LIKE'%%') ORDER BY film_title";
Which will always return the whole table.
Instead, do something like so:
Code: Select all
$query = "SELECT film_id, film_title, film_actors, film_description, film_year, film_location, film_backup FROM films WHERE (film_title LIKE '%$query_term%' OR film_actors LIKE'%$query_term%' OR film_year LIKE'%$query_term%') ORDER BY film_title";
Also - be aware that queries with leading wildcards (contains queries or "ends with" queries) are not indexable. Most RDBMSs (MySQL, Oracle, and Postgres) will always do a full table scan on these types of queries - making them slow down as the table gets larger. Stick with exact match, or begins with queries to take advantage of your indexing scheme, keep the tables small, or use synthetic data that you can index.
Cheers