Hello everyone, I have a db that has 3 query terms, one is text $searchterm which is text supplied by the user in a form. The other 2 are $searchtype and $search function which are text that are provided to the user from a drop down menu. The query is done based on the values of these variables.
You can see how this works at:
http://www.lightmypump.com/image-search/image-search_cont.php
The query looks like this
if ((!$searchterm == "") && (!$searchtype == "") && (!$searchfunction == ""))
$query = "SELECT * FROM LIST WHERE subject LIKE '%$searchterm%' AND type = '$searchtype' AND purpose = '$searchfunction' ORDER BY subject";
if all variables have a value then the query produces a list that selects content based on these values. The drop down menu offers the term “All” which in the query will be interpreted as requesting all the data in that field. To select for other conditions such as $searchtype has no value but $seachterm and $searchfunction do, I have to re-write the query.
Now I am planning to expand the database with many more fields and search variables, the permutations are incredibly large and I would have to write hundreds of queries for each case.
Is there a way to generalize the WHERE clause to avoid this? If I use the above query and there is nothing or its equivalent “All” in the variable $searchfunction then I get a o results reply to the query.
Cheer and thanks for any help, hopefully my question is clear
Jacques