1

I’m working on some script and I would like to create search. My project is based on CodeIgniter and my desire is to have all code content compatibile with it. I've already written question like that, but I didn't get enough help and nobody wants to help me, so I opened this question.

I have already working on the query for searching but it’s not good because it doesn’t support more words than one. So if I enter word “test” in my search form (assume that the test word is in database in one of fields) there will be few results, but if I enter words “test test test” (again assume that the test words are in database in one of fields) there will be no any result.

My previous query:

$this->db->select('title, content, date, hyperlink')->or_like(array('title' => $query, 'content' => $query))->order_by('id_article', 'desc')->get('news');

And after some tweaks:

$this->db->select('title, content, date, hyperlink');
foreach ($parts as $q)
{
    $this->db->or_like(array('title' => $q, 'content' => $q));
}
$this->order_by('id_article', 'desc')
$show_results = $this->db->get('news');

What's the best way to create good query?

1 Answer 1

1

Try out this code. This will help you more in your search query. It will search for any number of words wherever that word(s) exist.

$this->db->select('title, content, date, hyperlink');
$this->db->where("title LIKE '%$query%' OR content LIKE '%$query%'");

Hope this helps you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.