Multi criteria search
Posted: Wed Mar 14, 2007 7:53 am
Hi all,
I'm new to writing search scripts for your website, I've done it for a single field but
I'm experiencing some problems when using a form with multiple fields/criteria.
I have a form with multiple fields like name, surname, etc...
Which people can leave blank, so they decide which criteria they use to search the database.
I first tried it with an SQL Query using multiple > WHERE name LIKE '%name' AND surname LIKE ...
But that only gave results when all the fields were filled and matched correctly.
Then I changed the AND LIKE to OR LIKE but that just showed all the database entries.
I'm completely lost here, searched google but couldn't find any real usefull info {or am I not looking in the right places?}
Anyone has an idea on how to build your queries when having multiple criteria and partial matches..
For e.g if someone enters John Doe, but the database only contains a John Known it still shows it..
And should I use %..%, %... or ...% as a pattern?
I'm new to writing search scripts for your website, I've done it for a single field but
I'm experiencing some problems when using a form with multiple fields/criteria.
I have a form with multiple fields like name, surname, etc...
Which people can leave blank, so they decide which criteria they use to search the database.
I first tried it with an SQL Query using multiple > WHERE name LIKE '%name' AND surname LIKE ...
But that only gave results when all the fields were filled and matched correctly.
Then I changed the AND LIKE to OR LIKE but that just showed all the database entries.
I'm completely lost here, searched google but couldn't find any real usefull info {or am I not looking in the right places?}
Anyone has an idea on how to build your queries when having multiple criteria and partial matches..
For e.g if someone enters John Doe, but the database only contains a John Known it still shows it..
And should I use %..%, %... or ...% as a pattern?