Welcome Guest, Not a member yet? Register   Sign In
find a value exist or not using sql query
#1

[eluser]Bigil Michael[/eluser]
My Table Structure is like this

id name privileges

1 A 1,2,3,4,5


my Requirement is to find if 3 exist in column privileges if yes return true else return false

I write the query like this

Code:
$this->db->where_in('privileges', 3);
  $result_privileges = $this->obj->db->get('tablename');
  if($result_privileges->num_rows()>0){
   $privileges = $result_privileges->result();
    return TRUE;
  }
  return FALSE;

but it doesn't work

can any one help me ??


#2

[eluser]ivantcholakov[/eluser]
Your field "privileges" does not contain atomized values. You need an additional table.
http://en.wikipedia.org/wiki/First_normal_form
#3

[eluser]Tpojka[/eluser]
Yes, additional table would be neat solution.
Also, can you show (explain) us how do you insert records (privileges) into table?
Or can you echo that line (i.e. $result['privileges'])?
#4

[eluser]CroNiX[/eluser]
Code:
$this->db->where_in('privileges', array(3));  //array here




Theme © iAndrew 2016 - Forum software by © MyBB