Search Form

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
yoda69
Forum Newbie
Posts: 16
Joined: Wed Jun 20, 2007 10:21 am

Search Form

Post 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,
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Use a GROUP BY `id` clause (or some other field that uniquely identifies each row).
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply