Page 1 of 1

Search Form

Posted: Fri Aug 10, 2007 6:46 am
by yoda69
Hey people,

I'm trying to generate a search form that allows a user to search many fields (at mysql database) at the same time. my original thought was to use a SELECT statement that will use a WHERE clause containing several OR clauses. Example:

Code: Select all

SELECT count(*) as total FROM teachings WHERE (title LIKE '%a%' OR teacher LIKE '%a%' OR institution LIKE '%a%' OR countries LIKE '%a%' OR disciplines LIKE '%a%')
The problem is that i am getting many duplicated results (meaning results that are referring to the same row at the database). Can you recommend another approach for achieving what i am trying to achieve. Is it better to use several mysql statement in my PHP code or any other way?

Appreciate your comments.

Thanks ahead,

Posted: Fri Aug 10, 2007 7:42 am
by s.dot
Use a GROUP BY `id` clause (or some other field that uniquely identifies each row).