phpmysqlcodeigniterjoinfind-in-set

FIND_IN_SET() how to implement in mysql and codeigniter


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: enter image description here

2nd category: enter image description here


Solution

  • Try the following:

    SELECT u.user_id, GROUP_CONCAT(DISTINCT c.category_name) AS category_names, u.category_id, c.category_id
    FROM user u
    INNER JOIN category c ON c.category_id > 0 
    WHERE u.user_id = $user_id 
    GROUP BY u.user_id 
    HAVING FIND_IN_SET(c.category_id, u.category_id) > 0