1

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    demo@gmail.com 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'];
}
Alex Cohen
  • 5,596
  • 16
  • 54
  • 104
  • 2
    By the way, you should normalize your tables and use a separate table to connect the users to the categories. – jeroen Jun 16 '16 at 04:41
  • how the code, this code actualy for send notification item where user have been select category he want. If select category A,B,C user will send notif if in category A,B,C have new post.. – user2114764 Jun 16 '16 at 04:44

0 Answers0