• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FIND_IN_SET() how to implement in mysql and codeigniter

#1
I Have two table in Database here i put my two table and i want record like Ex> Suppose if user 1 is login and user category_id is 1,2,3 then i want record from 2nd table like Home,Marketing,Customer so how to fire query FIND_IN_SET() in mysql and Codeigniter

1st* user_registration
userid  roll_id   fullname    username          password               category_id
  1      1          admin     [email protected]   admin              1,2,3
  2      2         user         [email protected]        user             1,2,3,4,5,6

2nd*Category
category_id    cname         parentID      

 1                  Home                  0          
 2                Marketing              0             
 3                Customer              2             
 4                Quoation               2                 
 5            New Customer          3         
 6           view Customer           3
Reply

#2
Hi,

Use where_in with the content of the user's category_id field.
some thing like this:


PHP Code:
$this->db->where_in('category_id',$users->category_id)->get('category'); 
A good decision is based on knowledge and not on numbers. - Plato

Reply

#3
(08-01-2018, 11:40 PM)salain Wrote: Hi,

Use where_in with the content of the user's category_id field.
some thing like this:


PHP Code:
$this->db->where_in('category_id',$users->category_id)->get('category'); 

What is $users?
Reply

#4
that would be your model returned value (category_id) from your users table.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#5
(08-02-2018, 04:54 AM)InsiteFX Wrote: that would be your model returned value (category_id) from your users table.

i did not understand
Reply

#6
userid = 1 have this:
$users->category_id = array(1,2,3)
userid = 2 have this:
$users->category_id = array(1,2,3,4,5,6)

So:
$this->db->where_in('category_id',array(1,2,3))->get('category');
Reply

#7
(08-02-2018, 06:57 AM)jreklund Wrote: userid = 1 have this:
$users->category_id = array(1,2,3)
userid = 2 have this:
$users->category_id = array(1,2,3,4,5,6)

So:
$this->db->where_in('category_id',array(1,2,3))->get('category');

Thank YOu dear
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.