Better way to search for text in two columns

Posted by David on Programmers See other posts from Programmers or by David
Published on 2012-07-04T21:36:23Z Indexed on 2012/07/05 3:22 UTC
Read the original article Hit count: 225

Filed under:
|
|
|
|

Here is the scenario. I am making a custom blogging software for my site. I am implementing a search feature. It's not very sophisticated - basically it just takes the search phrase entered and runs this query:

$query="SELECT * FROM `blog` WHERE `title` LIKE '%$q%' OR `post` LIKE '%$q%'";

Which is meant to simply search the title and post body for the phrase entered. Is there a better way to do that, keeping in mind how long it would take to run the query on up to 100 rows, each with a post length of up to 1500 characters? I have considered using a LIMIT statement to (sometimes) restrict the number of rows that the query would examine. Good idea?

© Programmers or respective owner

Related posts about php

Related posts about sql