区别不起作用

时间:2016-02-05 12:13:01

标签: php mysql

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')

以上方式明显有效但在使用时......

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

就像这样明显不起作用


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

1 个答案:

答案 0 :(得分:0)

如果整数值中有id,则可以使用php的implode函数。 见下文:

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

如果有字符串作为类别名称,则使用下面的代码。

<?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.")";
}
?>