Get each category id from column table with separate comma to show value

+1 vote
asked Jun 16, 2016 by user2114764

I realy need help to fix this code. Actualy I want get gcm_id from table where the user selects several category from table category. An example of what I want main point is gcm_id data "gcm_id will show if user select category A,B,C" etc.. How do I do this in php mysql. I try FIND_IN_SET with no luck

uid | email          | gcm_id  | app_type | categories 

 1 xzxzxzxz    A           2,5,6

How get gcm_id if user have been select categories id 2,5, and 6?

the code :

if (!empty($cat)) {
        foreach ($cat as $key => $value) {
            $wc.="FIND_IN_SET('$value',categories) > 0 OR ";

    $pos = strrpos($wc, "OR");

    if ($pos !== false) {
        $wc = substr_replace($wc, "AND", $pos, strlen("OR"));

    $wc.=" is_active=1";

    $q = "select * from datanotif where app_type='$type' AND $wc ";

    $r = mysqli_query($mysqli,$q);
    $users = array();
    while ($row1 = mysqli_fetch_assoc($r)) {
        $users[] = $row1;

    $ids = array();
foreach ($users as $key => $value) {
    $ids[] = $value['gcm_id'];

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter