您的位置:首页 > 编程语言 > PHP开发

php创建mysql 查询IN('a','b')

2015-06-29 14:54 561 查看
function db_create_in($item_list, $field_name = '')

{

if (empty($item_list))

{

return $field_name . " IN ('') ";

}

else

{

if (!is_array($item_list))

{

$item_list = explode(',', $item_list);

}

$item_list = array_unique($item_list);

$item_list_tmp = '';

foreach ($item_list AS $item)

{

if ($item !== '')

{

$item_list_tmp .= $item_list_tmp ? ",'$item'" : "'$item'";

}

}

if (empty($item_list_tmp))

{

return $field_name . " IN ('') ";

}

else

{

return $field_name . ' IN (' . $item_list_tmp . ') ';

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: