MySQL Forums :: PHP :: mutiple field query


Advanced Search

mutiple field query
Posted by: Jacques Chaurette ()
Date: May 27, 2009 06:02AM

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

Options: ReplyQuote


Subject Written By Posted
mutiple field query Jacques Chaurette 05/27/2009 06:02AM
Re: mutiple field query Rick James 05/28/2009 07:25PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.