区别不起作用

1.

select sub_category from add_skills where skillax_id='28'

2.

select distinct skillax_id from add_skills where sub_category in('Nutrition 101','All About Juicing','Make Up 101')

above way distinct working but when m using...

select distinct skillax_id from add_skills where sub_category in('".$na['sub_category']."')

like this distinct not working


  1. select * from users where skillax_id in('28','23','5')
    

If there are ids in integer value then you can use implode function of php. See below:

<?php
$query = "select distinct skillax_id from add_skills where sub_category in(".implode(",",$na['sub_category']).")";
?>

If there are string as category name then use below code for that.

<?php
$str = "";
if(!empty($na['sub_category']))
{
    foreach($na['sub_category'] as $key=>$val)
    {
        if($str == "")
            $str .= "'".$val."'";
        else
            $str .= ",'".$val."'";
    }
    $query = "select distinct skillax_id from add_skills where sub_category in(".$str.")";
}
?>