Welcome Guest, Not a member yet? Register   Sign In
Searching in codeigniter
#1

[eluser]tj[/eluser]
hai i need to search a word from a lot of text and display it.it works fine on single word but when we use multiple words separated by a space it doesnot return any value my code is

function fetchblogscount($userid,$tag)
{
$this->db->select('feed_info.id,
feed_info.title,
feed_info.description ');
$this->db->from('feed_info');
$this->db->join('feeds', 'feed_info.feed_id= feeds.id');
$this->db->where('feeds.user_id', $userid);
$this->db->like('title', $tag);
$this->db->or_like('description',$tag);
$q = $this->db->get();
return $q->result_array();
}

tnx in advance
#2

[eluser]Jeremy Gimbel - Conflux Group[/eluser]
If you want to search a larger text field in your database for your $tag variable, you'll need to do something like this:

Code:
$this->db->like(‘title’, "%" . $tag . "%");

This basically says to look for $tag surrounded by any other characters. You can adjust accordingly if you want to include spaces around the word (ie. just searching for that word, not part of another word), etc.




Theme © iAndrew 2016 - Forum software by © MyBB