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]CI Coder[/eluser]
[quote author="tj" date="1258977806"]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[/quote]

Try the following: replace these lines
Code:
$this->db->like(‘title’, $tag);
$this->db->or_like(‘description’,$tag);

with these:

Code:
$this->db->like(‘title’, '%'.$tag.'%');
$this->db->or_like(‘description’,'%'.$tag.'%');
#3

[eluser]Isern Palaus[/eluser]
I think that you need to explode the search query and foreach search entry add and a or_like... I think that this will return more results.

Regards,
Isern
#4

[eluser]tj[/eluser]
$this->db->like(‘title’, '%'.$tag.'%');
$this->db->or_like(‘description’,'%'.$tag.'%');

this will not return any value any other idea
#5

[eluser]umefarooq[/eluser]
just print you query and see what is result

Code:
echo $this->db->last_query();
#6

[eluser]tj[/eluser]
i just fount my error .i have to use urldecode($tag).




Theme © iAndrew 2016 - Forum software by © MyBB