Page 1 of 1

Very simple question about searching

Posted: Mon Jan 05, 2009 4:41 am
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

Re: Very simple question about searching

Posted: Mon Jan 05, 2009 4:51 am
by VladSun
[sql]SELECT    * FROM    articles WHERE    title LIKE '%$keywords%'    OR    content LIKE '%$keywords%'ORDER BY   title LIKE '%$keywords%' DESC[/sql]

Re: Very simple question about searching

Posted: Tue Jan 06, 2009 2:33 am
by eyalrosen
Hi,
Thank you!