Welcome Guest, Not a member yet? Register   Sign In
DB Active record Solution need
#1

[eluser]bijon[/eluser]
Hi,

i want to get a search user list against a particular id and match the search string either first_name or last_name.
so i do the active record like :
Code:
//*****so many code before//

$this->db->select('*');
$this->db->form('table_name');
$this->db->like('first_name',$params['search']);
$this->db->or_like('last_name',$params['search']);
$this->db->where (array('id' => $id));
I execute the query . The query execute fine. But i do not get the required output.
i fournd that my query generate string is :
Code:
select * from table_name where id=1 and first_name like '%a%' or last_name like '%a%'


Though there is no name match against the id 1 , i still get output where output id shows may be 3 or 4.

So finally i found that if only last_name match then it returns the output . Not check the id. SO I Change the query string where add parenthesis (). I describe below my required query.THIS give me the correct output.
Code:
select * from table_name where id=1 and (first_name like '%a%' or last_name like '%a%')
So my question how can i create that above correct sql using active record.


thanks
saidur
http://saidur.wordpress.com




Theme © iAndrew 2016 - Forum software by © MyBB