Very simple question about searching

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
eyalrosen
Forum Newbie
Posts: 2
Joined: Mon Jan 05, 2009 4:29 am

Very simple question about searching

Post by eyalrosen »

Hello,
I have articles in my website. Each article has title and content. I also have a search page to search my articles. So currently whenever someone is searching I use the following query (PHP + MySQL):

($keywords = the search keywords)

SELECT * FROM articles WHERE title LIKE '%$keywords%' OR content LIKE '%$keywords%'

My question is how do I show first in the list (ORDER BY) results that has the keywords in the title and only after that results that has the keywords in the content?

Thanks! :D
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Very simple question about searching

Post by VladSun »

[sql]SELECT    * FROM    articles WHERE    title LIKE '%$keywords%'    OR    content LIKE '%$keywords%'ORDER BY   title LIKE '%$keywords%' DESC[/sql]
There are 10 types of people in this world, those who understand binary and those who don't
eyalrosen
Forum Newbie
Posts: 2
Joined: Mon Jan 05, 2009 4:29 am

Re: Very simple question about searching

Post by eyalrosen »

Hi,
Thank you!
Post Reply